|
Posted by Hemant on June 23, 2008, 3:48 pm
Please log in for more thread options >
>
>
> > When I try to expand file name in a loop, perl fails to expand
> > everyother file.
>
> > Example:
>
> > #!/usr/bin/perl
> > #
>
> use warnings;
> use strict;
>
> > @FileListArr = (
>
> my @FileListArr = (
>
> > "Full-2008-06-16-23:29:40",
> > "Incr-2008-06-17-22:02:18",
> > "Incr-2008-06-18-22:02:23",
> > "Incr-2008-06-19-22:02:20",
> > "Incr-2008-06-20-22:02:38",
> > "Incr-2008-06-21-22:05:30",
> > "Incr-2008-06-22-22:05:26",
> > );
>
> It is often more convenient to write a list like this as
>
> my @FileListArr = qw(
> Full-2008-06-16-23:29:40
> Incr-2008-06-17-22:02:18
> );
>
> > foreach $Volume (@FileListArr)
>
> foreach my $Volume (@FileListArr)
>
> > {
> > $File=glob("/backups/backupfiles/*/$Volume");
>
> glob in scalar context doesn't do what you think. Once you've invoked it
> once, it ignores its argument until it's returned all the possible
> results and then undef. If you just want the first result, you need to
> call it in list context like this:
>
> my ($File) = glob(...);
>
> where the parens around ($File) make this a list assignment (into a list
> with only one value) rather than a scalar assignment.
>
> Ben
>
> --
> Outside of a dog, a book is a man's best friend.
> Inside of a dog, it's too dark to read.
> b...@morrow.me.uk Groucho Marx
Thank you all for the quick replies.
|