![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| perl -write values in a file to @array in perl | meghana | Shell Programming and Scripting | 27 | 06-07-2009 06:05 PM |
| [Perl] Accessing array elements within a sed command in Perl script | userix | Shell Programming and Scripting | 2 | 10-03-2008 01:05 PM |
| how to get last value in an array in perl | meghana | Shell Programming and Scripting | 7 | 02-04-2008 05:12 PM |
| grep in array -perl | zedex | Shell Programming and Scripting | 1 | 12-06-2007 03:49 AM |
| join 2 array in perl? | gusla | Shell Programming and Scripting | 2 | 09-03-2004 10:59 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Perl Array Error when run - I think???
My code isn't pretty, my verbage isn't exact and I probably don't have all my facts together (story of my life). I know what I want with this script: to join three simple lines line 1,2,3 then repeat over and over again with 4,5,6 until the end of the file. the lines are the same, date,date,text. The text line will often end in a date however making things difficult for me, I think. My current code when run gives me this output:
ARRAY (0x99a03c) ARRAY (0x99a08c) ........... I imagine hidden behind all that is my data? </c> my $line = <fh>; # Skip first line die if !defined($line); $line = <fh>; # Skip second line die if !defined($line); $line = <fh>; while (defined($line) && $line !~ /^© Copyright/) { chomp( my $date1 = $line ); $line = <fh>; die if !defined($line); chomp( my $date2 = $line ); $line = <fh>; die if !defined($line); my $body = $line; $line = <fh>; my $body = ''; while ( defined($line) && $line !~ /^\d{2}\/\d{2}\/\d{4}$/ && $line !~ /^© Copyright/ ) { $body .= $line; $line = <fh>; } chomp( $body ); push @recs, [ $date1, $date2, $body ]; } print @recs, [ $date1, $date2, $body ]; foreach(@recs) { print "array element: $_\n"; } select ($out); printf @res; # Skip copyright line die if !defined($line); $line = <fh>; # Skip another line die if !defined($line); $line = <fh>; die if defined($line); close ($out); close (fh); </c> Thanks, Jon |
|
||||
|
Quote:
HOORAY!!! This got me past the annoying frosted glass problem. I can now see the two date fields. But what, pray tell, have I done wrong that is prohibiting the text field from showing up. The third line. Below is the actual data I am working with. The FIX you provided allows me to only view the Dates. Thanks again. Jon 01/16/2009 01/14/2009 Document #:R40129:> Projections of FY2009 Federal SCHIP Allotments Under CHIPRA 2009 01/16/2009 01/14/2009 Document #:R40130:> H.R. 2: The Children's Health Insurance Program Reauthorization Act of 2009 01/16/2009 01/13/2009 Document #:R40131:> Administrative Appeals in the Bureau of Land Management (BLM) and the Forest Service |
|
||||
|
Hard to say, your code is, well, uhh...... strange. If your file is consistent and its:
date date text date date text there is no need to do all that checking, just put the three lines into your array chomp(my $d1 = <fh>); chomp(my $d2= <fh>); chomp(my $line = <fh>); push @recs, [$di, $d2, $line]; |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|