Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Trying to capture a value from a list of values

by flexvault (Monsignor)
on Sep 02, 2015 at 10:40 UTC ( #1140776=note: print w/replies, xml ) Need Help??


in reply to Trying to capture a value from a list of values

parthodas,

Here's how I would like to see your script: ( YMMV )

use strict; . . . my @mylnxsrvrs = split(',', $myhash{SBLLNXSRVRHOSTS}); foreach my $something ( @mylnxsrvrs ) { my $lnxsrvr = "$something"; print "$something $lnxsrvr\n\n"; } print "$lnxsrvr\n"; ## Undefined now! print "@mylnxsrvrs";
Save the 'printf' for formatted printing, so that it becomes obvious upon review. And if you had used structures, you would have known that '$lnxsrvr' is undefined when you exit the 'foreach' loop. Perl allows for generous whitespace, so use whitespace to help you follow the flow of your work. Originally when I looked at your code, I didn't notice the closure to the 'foreach' loop.

But I suspect your problem is in the 'split' and without seeing what '$myhash{SBLLNXSRVRHOSTS})' looks like, we can't help solve your problem.

Regards...Ed

"Well done is better than well said." - Benjamin Franklin

Replies are listed 'Best First'.
Re^2: Trying to capture a value from a list of values
by parthodas (Acolyte) on Sep 02, 2015 at 11:36 UTC
    '$myhash{SBLLNXSRVRHOSTS})' has server names like -- dvapoms1,dvapoms2
    The code shows below things --
    @mylnxsrvrs = split(',', $myhash{SBLLNXSRVRHOSTS}); @mywinsrvrs = split(',', $myhash{SBLWINSRVRHOSTS}); @mysblroot = split(',', $myhash{SIEBELROOT}); @mysblsrvrpath = (',',$myhash{SBLSRVRPATH}); foreach $something (@mylnxsrvrs) {my $lnxsrvr = "$something"; printf "$something $lnxsrvr\n\n";} ##dvapoms1 dvapoms1 ##dvapoms2 dvapoms2 printf "$lnxsrvr\n"; ##"shows null" printf "@mylnxsrvrs"; ##dvapoms1 dvapoms2
    Hope this clears the point. I need to catch dvapoms1 in $lnxsrvr.
      Why have you completely ignored Ed's advice?

      To get the first value of your array:
      my $first_value = $mylnxsrvrs[0];
        I did not ignored Ed's advise. But could not apply it. Though using my $first_value = $mylnxsrvrs[0]; solved my issue. Thanks a lot.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1140776]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2020-09-19 03:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If at first I donít succeed, I Ö










    Results (114 votes). Check out past polls.

    Notices?