Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

hi

actually i would like to move the line into different file if prefix matching 628. could u please advice about the code as the output is not correct. thanks

File Input
621001000286 2/13/2013 18:42 3/15/2013 18:42 627001000298 3/13/2013 13:20 4/12/2013 13:20 628001000796 3/12/2013 19:07 4/11/2013 19:07 628001000823 3/13/2013 13:28 4/12/2013 13:28 629001001592 2/8/2013 15:52 3/10/2013 15:52
Output1
621001000286 2/13/2013 18:42 3/15/2013 18:42 627001000298 3/13/2013 13:20 4/12/2013 13:20 629001001592 2/8/2013 15:52 3/10/2013 15:52
Output 2
628001000796 3/12/2013 19:07 4/11/2013 19:07 628001000823 3/13/2013 13:28 4/12/2013 13:28
#!/usr/bin/perl use strict; use warnings; my $file = $ARGV[0] or die "Need to get CSV file on the command line\n +"; my $outfile = $ARGV[1] or die "Need to get output file on the command +line\n"; my $sum = 0; open(my $data, '<', $file) or die "Could not open '$file' $!\n"; open (OUTFILE, "> $outfile") || die "ERROR: opening $outfile\n"; open (OUTFILE_1, "> 1$outfile") || die "ERROR: opening $outfile\n"; while (my $line = <$data>) { chomp $line; my @fields = split "," , $line, -1;; my $sum = "$fields[0]"; #$fields[1] = "$sum"; if ($sum =~ /^628?$/ ) { #s/^628+//; $line= join( ",", @fields ) . "\n" ; print OUTFILE ("$line"); } else { $line= join( ",", @fields ) . "\n" ; print OUTFILE_1 ("$line"); } } close ($data); close (OUTFILE); close (OUTFILE_1);

In reply to move the line if prefix matching by hyans.milis

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others wandering the Monastery: (8)
    As of 2014-11-22 16:54 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My preferred Perl binaries come from:














      Results (123 votes), past polls