- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: how to access elemt in array from perl
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
тАО07-30-2009 03:03 AM
тАО07-30-2009 03:03 AM
I have one array say:
a=('jan','feb','mar','apr','may','june','jul') ,[(2,4)];
i am not able to compile thsi statment. It gives me the error like:
Can't modify constant item in scalar assignment at af.pl line 2, near "),"
Execution of af.pl aborted due to compilation errors.
And also what is the difference betwenn [] and [()] operatores in accessing the elements.
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-30-2009 03:09 AM
тАО07-30-2009 03:09 AM
Re: how to access elemt in array from perl
A tutorial:
http://www.comp.leeds.ac.uk/Perl/associative.html
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-30-2009 04:01 AM
тАО07-30-2009 04:01 AM
SolutionIt's not clear exactly what you are trying to do. You need to specify and array with the '@' sigil. Then it appears that you want an array slice of elements 2 and 4. Something like this:
#!/usr/bin/perl
use strict;
use warnings;
my @a=('jan','feb','mar','apr','may','june','jul');
print join ' ', @a[(2,4)], "\n";
my @b=qw( jan feb mar apr may june jul);
print join ' ', @b[2,4], "\n";
...You should use the 'strict' and 'warnings' pragmas as they will expose many errors.
You can drop the inner parentheses from the slice as I show in the second example.
@ SEP: You say you know Perl. You should know then that this was a simple array and not a hash.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-30-2009 04:31 AM
тАО07-30-2009 04:31 AM
Re: how to access elemt in array from perl
Many thanks
Both the outputs are same. It means
@b[2,4]=@b[(2,4)]
If both are same then why () is used, is any specify significance of this?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-30-2009 04:49 AM
тАО07-30-2009 04:49 AM
Re: how to access elemt in array from perl
I don't know of any reason why the parenthesis would have been used. There's nothing to evalulate before the slice is taken.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-30-2009 08:59 PM
тАО07-30-2009 08:59 PM
Re: how to access elemt in array from perl
Thanks a lot. That is fine for me.
Thanks
Diwakar