Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: split line from one point

by Anonymous Monk
on Oct 19, 2011 at 12:31 UTC ( [id://932380]=note: print w/replies, xml ) Need Help??


in reply to split line from one point

See Tutorials: Context in Perl: Context tutorial

split, in scalar context, returns the number of fields found, so you need to use list context

See also autodie and Modern Perl: the free book

#!/usr/bin/perl -- #~ 2011-10-19-05:27:59PDT by Anonymous Monk #~ perltidy -csc -otr -opr -ce -nibc -i=4 use strict; use warnings; use autodie; # dies if open/close... fail Main( @ARGV ); exit( 0 ); sub Main { if ( @_ == 2 ) { NotDemoMeaningfulName(@_); } else { Demo(); print '#' x 33 ,"\n", Usage(); } } ## end sub Main sub NotDemoMeaningfulName { my( $transaction, $res ) = @_; open my($in), '<', $transaction; open my($re), '>', $res; while( <$in> ){ my( $left, $right ) = split /T/, $_, 2; print $re $left; } close $in; close $re; } ## end sub NotDemoMeaningfulName sub Usage { <<"__USAGE__"; $0 $0 dataFile newDataFile perl ${\__FILE__} perl ${\__FILE__} dataFile newDataFile __USAGE__ } ## end sub Usage sub Demo { my ( $Input, $WantedOutput ) = DemoData(); NotDemoMeaningfulName( \$Input, \my $Output ); require Test::More; Test::More::is( $Output, $WantedOutput, ' NotDemoMeaningfulName Works Aas Designed' ); Test::More::done_testing(); } ## end sub Demo sub DemoData { my $One = <<'__One__'; 2010-12-01T21:15:40.000+01:00 2010-12-01T23:28:04.000+01:00 __One__ my $Two = <<'__Two__'; 2010-12-01 2010-12-01 __Two__ return $One, $Two; } ## end sub DemoData __END__

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://932380]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2024-03-19 14:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found