Computing.Net > Forums > Programming > Perl Script

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

Reply to Message Icon

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.



Sponsored Link
Ads by Google

Response Number 1
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.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Perl Script

Perl script - add text to a jpg ima www.computing.net/answers/programming/perl-script-add-text-to-a-jpg-ima/3331.html

Perl Script Problem www.computing.net/answers/programming/perl-script-problem/7932.html

Perl Script with MySQL eating CPU www.computing.net/answers/programming/perl-script-with-mysql-eating-cpu/7781.html