Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.
Perl Script
Name: Jawn Date: September 29, 2008 at 20:57:05 Pacific OS: ubuntu CPU/Ram: 2048 Product: homemade
Comment:
Hello, I was writing a script that is going to parse a text file. I had some questions though as I am new to Perl. When I first input the file into an array is it possible to have it input into a multidimensional array instead of inputting per line per array.
Secondly it uses spaces and a random number of spaces to separate the columns. When I use the split command how can I account for this as a 1 space delimiter doesn't work.
Name: Jawn Date: September 29, 2008 at 21:07:21 Pacific
Reply:
Also, here is a line from the file being inputted:
Date Time AM/PM Name Size
As you can see there isn't a set delimiter. I was considering trying to remove the spaces and then add the delimiter. But I wanted to see what other options I had.
0
Response Number 2
Name: ghostdog Date: September 29, 2008 at 22:01:29 Pacific
Reply:
show a sample of your file, not just a line, and then describe your expected output.
0
Response Number 3
Name: FishMonger Date: September 30, 2008 at 05:20:28 Pacific
Reply:
You can put your data into any data structure you wish, but you haven't provided enough info for us to help you.
The split function takes a regex as its first argument, so if you need to split on an unknown number of spaces, then use:
my @array = split /\s+/, $line;
For more specific help, you need to provide us with several lines from your data file and tell us exactly what you want to do with the data. We will also need to see some or all of your script so that we can show how you can fix it.
0
Response Number 4
Name: Jawn Date: September 30, 2008 at 08:53:22 Pacific
Reply:
Awesome, many thanks for the help Ghostdog and Fishmonger. The \s+ delimiter did the trick.
Summary: Are you having a problem with a shell script or a Perl script? Start by reading the man page for grep. Also, if you post the portion of the script that is giving you the problem, we might be better ...
Summary: hello all, i'm using a Perl script to read an old database then convert to a new schema. For every record read (currently around 15k, but in production 100k), the script could generate anywhere ...