![]() |
|
|
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 |
| How to store values into variable in perl | chittiprasad15 | Linux | 3 | 05-08-2008 01:21 AM |
| Need help to write a Perl script | user_prady | Shell Programming and Scripting | 10 | 03-26-2008 02:38 AM |
| how to get last value in an array in perl | meghana | Shell Programming and Scripting | 7 | 02-04-2008 05:12 PM |
| formating array file output using perl | seismic_willy | Shell Programming and Scripting | 4 | 03-22-2007 02:23 AM |
| need help to write perl code | getdpg | Shell Programming and Scripting | 0 | 09-20-2006 10:24 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
So if below works on a single column datafile of
Apple B34 Cat 112 245 356 Outputs to screen: 112 Apple 245 B34 356 Cat open(FILE, "<", "dataFile"); while(<FILE>) { chomp; if ($_ =~ /^[[:digit:]]+$/) { push @intArray, $_; } elsif (($_ =~ /^[[:alpha:]]+$/)||($_ =~ /^[[:alnum:]]+$/)) { push @stringArray, $_; } } close(FILE); $lengthArray=@intArray; for($i=0; $i<$lengthArray; $i++) { print"\n$intArray[$i] $stringArray[$i] "; } How can I take a datafile that has a special character and have mult arrays. First array catches everything before the special character “$” and the second array catches everything after the special character? Abc is good for me $4.55 Def might not be enough $5.66 Ghi price to play $6.77 /r Rick |
|
||||
|
In script form: Code:
my @before;
my @after;
open(FILE, "<", "dataFile");
while(<FILE>) {
chomp;
my ($before, $after) = split(/\$/);
push @before, $before;
push @after, $after;
}
for my $i (0 .. $#before) {
print "$before[$i] $after[$i]\n";
}
Assumes all lines have the '$' character in them, if not, adjust accordingly. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|