Loading ...
Sorry, an error occurred while loading the content.

really beginer

Expand Messages
  • Toma H
    I need to know if is possible to split a file in perl I will provide data here about what I need I need to split data from a file like this location1/nume
    Message 1 of 4 , Nov 3, 2010
    • 0 Attachment
      I need to know if is possible to split a file in perl I will provide data here about what I need

      I need to split data from a file like this
      location1/nume /telefon/email
      location1/nume /telefon/email
      location1/nume /telefon/email
      location1/nume /telefon/email
      location2/nume /telefon/email
      location2/nume /telefon/email
      location3/nume /telefon/email
      location3/nume /telefon/email
      location4/nume /telefon/email
      location4/nume /telefon/email
      location5/nume /telefon/email
      location5/nume /telefon/email
      location6/nume /telefon/email
      location6/nume /telefon/email
      location7/nume /telefon/email
      location7/nume /telefon/email
      location8/nume /telefon/email
      location8/nume /telefon/email
      location9/nume /telefon/email
      location9/nume /telefon/email

      in more files like
      filename1: location1_address.txt
      location1/nume /telefon/email
      location1/nume /telefon/email
      location1/nume /telefon/email
      location1/nume /telefon/email

      filename2: location2_address.txt
      location2/nume /telefon/email
      location2/nume /telefon/email

      and like this for all.
      Please tell me if it can be possible and if someone can help me with this
      Thanks a lot
    • a_z0_9_blah
      ... Its really not good to provide questioners with solutions if they haven t tried themselves. Otherwise, how would they learn? This may accomplish what you
      Message 2 of 4 , Nov 3, 2010
      • 0 Attachment
        --- In perl-beginner@yahoogroups.com, "Toma H" <horatiutoma@...> wrote:
        >
        > I need to know if is possible to split a file in perl I will provide data here about what I need
        >

        Its really not good to provide questioners with solutions if they haven't tried themselves. Otherwise, how would they learn?

        This may accomplish what you described.

        #!/usr/bin/perl
        use strict;
        use warnings;

        chomp(my $line = <DATA>);
        my ($previous_loc) = $line =~ /(\d+)/;

        open my $fh, ">", "location${previous_loc}_address.txt" or die $!;
        print $fh $line, "\n";

        while (<DATA>) {
        chomp;
        my ($location) = /(\d+)/;
        if ($previous_loc != $location) {
        close $fh or die $!;

        open $fh, ">", "location${location}_address.txt" or die $!;
        print $fh $_, "\n";

        $previous_loc = $location;
        }
        else {
        print $fh $_, "\n";
        }
        }
        close $fh or die $!;

        __DATA__
        location1/nume/telefon/email
        location1/nume/telefon/email
        location1/nume/telefon/email
        location1/nume/telefon/email
        location2/nume/telefon/email
        location2/nume/telefon/email
        location3/nume/telefon/email
        location3/nume/telefon/email
        location4/nume/telefon/email
        location4/nume/telefon/email
        location5/nume/telefon/email
        location5/nume/telefon/email
        location6/nume/telefon/email
        location6/nume/telefon/email
        location7/nume/telefon/email
        location7/nume/telefon/email
        location8/nume/telefon/email
        location8/nume/telefon/email
        location9/nume/telefon/email
        location9/nume/telefon/email
        location10/nume/telefon/email
      • Urban Gabor
        HI, an other solution is the split function and build a hash of the data. Read CPAN for more details. BTW you are supposed to try by yourself first, and google
        Message 3 of 4 , Nov 4, 2010
        • 0 Attachment
          HI, an other solution is the split function and build a hash of the data. Read CPAN for more details. BTW you are supposed to try by yourself first, and google a bit for ideas.....

          Gabaux
          Linux is like a wigwam: no gates, no windows, and an apache inside!

          Toma H <horatiutoma@...> �rta:
          >

          > I need to know if is possible to split a file in perl I will provide data here about what I need
          >
          >I need to split data from a file like this
          >location1/nume /telefon/email
          >location1/nume /telefon/email
          >location1/nume /telefon/email
          >location1/nume /telefon/email
          >location2/nume /telefon/email
          >location2/nume /telefon/email
          >location3/nume /telefon/email
          >location3/nume /telefon/email
          >location4/nume /telefon/email
          >location4/nume /telefon/email
          >location5/nume /telefon/email
          >location5/nume /telefon/email
          >location6/nume /telefon/email
          >location6/nume /telefon/email
          >location7/nume /telefon/email
          >location7/nume /telefon/email
          >location8/nume /telefon/email
          >location8/nume /telefon/email
          >location9/nume /telefon/email
          >location9/nume /telefon/email
          >
          >in more files like
          >filename1: location1_address.txt
          >location1/nume /telefon/email
          >location1/nume /telefon/email
          >location1/nume /telefon/email
          >location1/nume /telefon/email
          >
          >filename2: location2_address.txt
          >location2/nume /telefon/email
          >location2/nume /telefon/email
          >
          >and like this for all.
          >Please tell me if it can be possible and if someone can help me with this
          >Thanks a lot
          >
          >


          [Non-text portions of this message have been removed]
        • Toma H
          I have did this but I can not finish it :( http://codepad.org/YiqZWflu
          Message 4 of 4 , Nov 4, 2010
          • 0 Attachment
            I have did this but I can not finish it :(
            http://codepad.org/YiqZWflu

            --- In perl-beginner@yahoogroups.com, Urban Gabor <gabaux@...> wrote:
            >
            > HI, an other solution is the split function and build a hash of the data. Read CPAN for more details. BTW you are supposed to try by yourself first, and google a bit for ideas.....
            >
            > Gabaux
            > Linux is like a wigwam: no gates, no windows, and an apache inside!
            >
            > Toma H <horatiutoma@...> írta:
            > >
            >
            > > I need to know if is possible to split a file in perl I will provide data here about what I need
            > >
            > >I need to split data from a file like this
            > >location1/nume /telefon/email
            > >location1/nume /telefon/email
            > >location1/nume /telefon/email
            > >location1/nume /telefon/email
            > >location2/nume /telefon/email
            > >location2/nume /telefon/email
            > >location3/nume /telefon/email
            > >location3/nume /telefon/email
            > >location4/nume /telefon/email
            > >location4/nume /telefon/email
            > >location5/nume /telefon/email
            > >location5/nume /telefon/email
            > >location6/nume /telefon/email
            > >location6/nume /telefon/email
            > >location7/nume /telefon/email
            > >location7/nume /telefon/email
            > >location8/nume /telefon/email
            > >location8/nume /telefon/email
            > >location9/nume /telefon/email
            > >location9/nume /telefon/email
            > >
            > >in more files like
            > >filename1: location1_address.txt
            > >location1/nume /telefon/email
            > >location1/nume /telefon/email
            > >location1/nume /telefon/email
            > >location1/nume /telefon/email
            > >
            > >filename2: location2_address.txt
            > >location2/nume /telefon/email
            > >location2/nume /telefon/email
            > >
            > >and like this for all.
            > >Please tell me if it can be possible and if someone can help me with this
            > >Thanks a lot
            > >
            > >
            >
            >
            > [Non-text portions of this message have been removed]
            >
          Your message has been successfully submitted and would be delivered to recipients shortly.