Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: split line from one point

by Anonymous Monk
on Oct 19, 2011 at 12:31 UTC ( #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__


Comment on Re: split line from one point
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (16)
As of 2015-07-06 12:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (74 votes), past polls