"Charles K. Clarkson" <[EMAIL PROTECTED] To .net> <beginners-cgi@perl.org> cc 10/21/2005 12:24 PM Subject RE: implementing links on a system command output
[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> wrote: : The difficulty is that $_ is an entire block of data that : includes more than just H strings and therefore I cannot link : all of $_ which is why I placed just the H strings from $_ in an : array. From this array, I was thinking of traversing : through, running the command to get the capacity data. Here's what I am gleaming from your words. When you say $_ you are referring to this part of the script: open (ARC, "archiver -v |") or error(); foreach (<ARC>) { "archiver -v |" returns this. fs_heartlab.1 sort:path media: sg Volumes: H01192 H01193 H01195 H01196 H01197 Total space available: 111.3G fs_heartlab.2 sort:path media: sf Volumes: H02047 H02048 H02051 H02052 H02000 H02039 H02040 H02041 Total space available: 527.8G So, as a test case, we can use this script. DATA is the same as ARC above, but now everyone on this list can play with the code. I use 'while' instead of 'foreach' because it is the more common idiom in this situation. #!/usr/bin/perl use strict; use warnings; while ( <DATA> ) { # do something } __END__ fs_heartlab.1 sort:path media: sg Volumes: H01192 H01193 H01195 H01196 H01197 Total space available: 111.3G fs_heartlab.2 sort:path media: sf Volumes: H02047 H02048 H02051 H02052 H02000 H02039 H02040 H02041 Total space available: 527.8G Now, if I am not mistaken your task is to strip only the "H strings" from this list and place it into an array. Since I am mentally unable to name an array variable with a name containing the word "array", I will be using the name @h_strings. #!/usr/bin/perl use strict; use warnings; my @h_strings; while ( <DATA> ) { chomp; push @h_strings, $1 if /\s*(H\d{5})/i; } print "$_\n" foreach @h_strings; __END__ fs_heartlab.1 sort:path media: sg Volumes: H01192 H01193 H01195 H01196 H01197 Total space available: 111.3G fs_heartlab.2 sort:path media: sf Volumes: H02047 H02048 H02051 H02052 H02000 H02039 H02040 H02041 Total space available: 527.8G Now @h_strings contains this. Which I believe provides you with the array you needed to run your command. H01192 H01193 H01195 H01196 H01197 H02047 H02048 H02051 H02052 H02000 H02039 H02040 H02041 To step through the array, you could use foreach. foreach my $h_string ( @h_strings ) { # Do something with $h_string. } If you want to do it all in one step, this would work. #!/usr/bin/perl use strict; use warnings; while ( <DATA> ) { chomp; next unless /\s*(H\d{5})/i; my $h_string = $1; # Do something with $h_string. } __END__ To translate that back to your subroutine, we would do this. sub viewhrtlab { # Don't clobber ARC if it is already open somewhere else. local *ARC; open (ARC, "archiver -v |") or error(); while ( <ARC> ) { chomp; next unless /\s*(H\d{5})/i; my $h_string = $1; # Do something with $h_string. } } HTH, Charles K. Clarkson -- Mobile Homes Specialist 254 968-8328 ****************************************************** ****************************************************** thx Charles, but your code is something I did knew already. I need to implement a link for each H string and I do not see this??? I think we are part way there as in producing the capacity data sets from the array, but my problem was the <A HREF> with pointing to another page using "file.pl?H_string" So in the FH reference local *ARC; once its open, I can just reuse the reference right? Does the FH have to still be open in order to reuse it? *FH is a typeglob? \*FH is a reference? cant I assign either one to a scalar? what is the difference between the two? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response> -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>