[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
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>