- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- perl - more concise way to split scalar string int...
Operating System - HP-UX
1820390
Members
3390
Online
109623
Solutions
Forums
Categories
Company
Local Language
юдл
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
юдл
back
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
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- 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
тАО08-02-2004 04:52 AM
тАО08-02-2004 04:52 AM
perl - more concise way to split scalar string into 2-dimensional array ?
In the interest of improving my perl skills, is there a better way to write the following piece of code?
@lines = split /^/, $response->content();
foreach $line (@lines) {
($mtime, $filename) = split /" "/, $line;
@tmp = ($mtime,$filename);
push @APfiles,[@tmp];
}
response->content is returned from the LWP::UserAgent module; it is a scalar, string, containing a bunch of filenames and mtimes. The purpose of my code, above, is to convert the string to a 2 dimensional array, where each "row" is an mtime and a filename. It works the way I've written it, but I'm just wondering if there's a more perl-ish way of doing it.
- John
@lines = split /^/, $response->content();
foreach $line (@lines) {
($mtime, $filename) = split /" "/, $line;
@tmp = ($mtime,$filename);
push @APfiles,[@tmp];
}
response->content is returned from the LWP::UserAgent module; it is a scalar, string, containing a bunch of filenames and mtimes. The purpose of my code, above, is to convert the string to a 2 dimensional array, where each "row" is an mtime and a filename. It works the way I've written it, but I'm just wondering if there's a more perl-ish way of doing it.
- John
- Tags:
- Perl
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-02-2004 05:51 AM
тАО08-02-2004 05:51 AM
Re: perl - more concise way to split scalar string into 2-dimensional array ?
Hmm,
Surely you can just drop the mtime and filename variables like:
@tmp=split /" "/, $line;
And if you have $_ 'free to use' then you can probably simply with
foreach $_ (@lines) {
@tmp = split;
:
Now can you also use:
foreach $_ (@lines) {
push @APfiles, split;
}
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-02-2004 06:28 AM
тАО08-02-2004 06:28 AM
Re: perl - more concise way to split scalar string into 2-dimensional array ?
Thank you Hein.
The first suggestion worked, like this:
@lines = split /^/, $response->content();
foreach $line (@lines) {
@tmp=split /" "/, $line;
push @APfiles,[@tmp];
}
And the second worked, like this:
@lines = split /^/, $response->content();
foreach $_ (@lines) {
@tmp=split;
push @APfiles,[@tmp];
}
But the following isn't working for me yet, still puzzling over why...
@lines = split /^/, $response->content();
foreach $_ (@lines) {
push @APfiles,split;
}
The first suggestion worked, like this:
@lines = split /^/, $response->content();
foreach $line (@lines) {
@tmp=split /" "/, $line;
push @APfiles,[@tmp];
}
And the second worked, like this:
@lines = split /^/, $response->content();
foreach $_ (@lines) {
@tmp=split;
push @APfiles,[@tmp];
}
But the following isn't working for me yet, still puzzling over why...
@lines = split /^/, $response->content();
foreach $_ (@lines) {
push @APfiles,split;
}
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Learn About
News and Events
Support
© Copyright 2025 Hewlett Packard Enterprise Development LP