- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Perl script - can someone enlighten me?
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
Discussions
Discussions
Forums
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
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
тАО08-04-2004 02:21 AM
тАО08-04-2004 02:21 AM
Here's the quick synopsis. I read a file which contains months and data. Using $month I add data to an array of this name as an element (i.e $month[1]=1). Lets say $month = Jan - if I foreach(@month) I get my elements OK. If I foreach(@Jan) I get nada!!
Please find a really cut down version of what I'm trying to do attached and the output. The file being opened contains the string 'Jan'.
Thanks for any help,
Tony
Solved! Go to Solution.
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-04-2004 03:01 AM
тАО08-04-2004 03:01 AM
Re: Perl script - can someone enlighten me?
Now I have a different problem. I put all my months into an array a la @months=qw(blah blah) then I want to foreach each element in each month array like this:
foreach (@months){
foreach(@_){ #read as for each element in @Jan
do something
}
}
but this doesn't work. Any tips?
Thanks,
Tony
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-04-2004 03:22 AM
тАО08-04-2004 03:22 AM
Re: Perl script - can someone enlighten me?
http://pleac.sourceforge.net/pleac_perl/datesandtimes.html
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-04-2004 07:07 AM
тАО08-04-2004 07:07 AM
Re: Perl script - can someone enlighten me?
I would jst spend the extra four bytes and name your foreach return.
This works for me... is it what you wanted to achieve?
@aap=qw(een twee drie);
@noot=qw(vier vijf zes);
@mies=qw(zeven);
@months=qw(aap noot mies);
foreach $m (@months) {
print "$m\n";
foreach (@$m) {
print "m=$m _=$_\n";
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-04-2004 07:29 AM
тАО08-04-2004 07:29 AM
SolutionDON'T!
Whenever you are tempted to do so, use a hash instead.
Your solution would be
my @jan = (1 .. 31);
my @feb = (1 .. 28);
:
foreach my $month (@month) {
foreach my $day (@$month) {
...
}
}
which is better to be done using a hash
my %month = (
jan => [ 1 .. 31 ],
feb => [ 1 .. 28],
);
foreach my $month (@month) {
foreach my $day (@{$month{$month}}) {
...
}
}
Enjoy, Have Fun! H.Merijn