- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Perl split function question
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2010 04:14 AM
06-30-2010 04:14 AM
CODE:
#!/usr/bin/perl -w
$FILE = 'pnm_om.06_14_2010.0030.ISBLTUGS01D.OT.CSV';
open(FILE) or die ("Could not open file.");
{ local $/; $content =
@column = split(/[\s]*[,][\s]*/,$content);
#@column = split(/\n/,$column);
for ( $I = 0; $I <= 80; $I++ ) {
print "ARRAY $I : $column[$I]\n";
}
RESULT:
ARRAY 0 : Date
ARRAY 1 : Time
ARRAY 2 : Switch Name
ARRAY 3 : Group Name
.....
ARRAY 65 : Reg31 Name
ARRAY 66 : Reg31 Value
ARRAY 67 : Reg32 Name
ARRAY 68 : Reg32 Value
06-14-2010
ARRAY 69 : 00:30:08
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2010 04:20 AM
06-30-2010 04:20 AM
Re: Perl split function question
#!/usr/bin/perl -w
$FILE = 'pnm_om.06_14_2010.0030.ISBLTUGS01D.OT.CSV';
open(FILE) or die ("Could not open file.");
{ local $/; $content =
@column = split(/[\s]*[,\n][\s]*/,$content);
#@column = split(/\n/,$column);
for ( $I = 0; $I <= 80; $I++ ) {
print "ARRAY $I : $column[$I]\n";
}
does it sound logical ??
Thanks in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2010 04:31 AM
06-30-2010 04:31 AM
Re: Perl split function question
> does it sound logical ??
If this works for your data then, OK.
You should use (as Merijn pointed out in an earlier thread of yours) the 'Text::CSV' module to parse CSV data.
Why are you slurping the whole file rather than reading a one line at a time?
You should be using 'use strict'. This will save you from making stupid mistakes and wasting hours chasing them down.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2010 04:58 AM
06-30-2010 04:58 AM
Re: Perl split function question
Because its dependency is some C stuff like cc that is not available in customer environment,
>Why are you slurping the whole file rather than reading a one line at a time?
Speed!
I already wrote a code with test purpose Text::CSV (older version of Merijn wrote) ,and tried, it was so slow to process my input file .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2010 05:15 AM
06-30-2010 05:15 AM
SolutionYou could do things more Perl-ishly and rigorously like:
#!/usr/bin/perl
use strict;
use warnings;
my $file = '/tmp/mycsv';
my ( $fh, $content, @column );
open( $fh, '<', $file ) or die("Could not open '$file'");
{
local $/;
$content = <$fh>;
}
@column = split( /\s*[,\n]\s*/, $content );
my $j = 0;
for my $i (@column) {
print "ARRAY", $j++, " : ", "$i\n";
}
1;
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2010 07:55 AM
08-12-2010 07:55 AM
Re: Perl split function question
--Geoff