From: elsiddik on
well i wanted to just mess a little with perl and try if it can give
me the same result of a small shell script i wrote a little while ago
but it doesnt seems to work out with me . here is my shell script

#!/bin/bash
DIRECTORY="/usr/bin"
for file in $DIRECTORY/*
do whatis `basename $file`

done
exit 0

i tried to run a similiar perl code by typing on command line.

perl -e "system qw (whatis /usr/bin/*)"

but its not giving me the same whatislog - what am i doing wrong ?

cheers.


zaher el siddik

From: Paul Lalli on
On May 1, 7:22 am, elsiddik <elsid...(a)gmail.com> wrote:
> well i wanted to just mess a little with perl and try if it can give
> me the same result of a small shell script i wrote a little while ago
> but it doesnt seems to work out with me . here is my shell script
>
> #!/bin/bash
> DIRECTORY="/usr/bin"
> for file in $DIRECTORY/*
> do whatis `basename $file`
>
> done
> exit 0
>
> i tried to run a similiar perl code by typing on command line.
>
> perl -e "system qw (whatis /usr/bin/*)"
>
> but its not giving me the same whatislog - what am i doing wrong ?

You are using the qw operator. This operator takes a space-separated
list of barewords and returns a quoted list of words. That is, your
system() call is equivalent to:
system('whatis', '/usr/bin/*');

When you call system() with two or more arguments, Perl executes the
first argument directly, passing in the remaining arguments. It does
not spawn a shell at all. So the * in the second argument there is
not interpreted by any shell to mean "all files", because there is no
shell to do the interpreting. So you are litterally calling "whatis"
on the single argument "/usr/bin/*". Since no such file with that
name exists, there is no output.

Change your qw() to qq() or q(), and read up on `perldoc -f system`
for more information.

Paul Lalli

From: Klaus on
> > On May 1, 7:22 am, elsiddik <elsid...(a)gmail.com> wrote:
> > > perl -e "system qw (whatis /usr/bin/*)"
> > > but its not giving me the same whatislog - what am i doing wrong ?

> On May 1, 10:45 pm, Paul Lalli <mri...(a)gmail.com> wrote:
> > You are using the qw operator.
> > Change your qw() to qq() or q()

On May 1, 3:11 pm, elsiddik <elsid...(a)gmail.com> wrote:
> well i tried running the code with q and qq
> my $path = "/usr/bin/";
> system "whatis $path";
> its confusing me big time.

It's confusing you, probably because you forgot to put an asterisk at
the end of /usr/bin/

--
Klaus

From: Paul Lalli on
> > On May 1, 7:22 am, elsiddik <elsid...(a)gmail.com> wrote:
>
> > > perl -e "system qw (whatis /usr/bin/*)"
>
> > > but its not giving me the same whatislog - what am i doing wrong ?
>
> > You are using the qw operator. This operator takes a space-separated
> > list of barewords and returns a quoted list of words. That is, your
> > system() call is equivalent to:
> > system('whatis', '/usr/bin/*');
>
> > Change your qw() to qq() or q(), and read up on `perldoc -f system`
> > for more information.

> well i tried running the code with q and qq but im still getting the
> same output --

I don't believe you. Please post a short-but-complete script that
demonstrates this, like so:

$ perl -e'system qq(whatis /usr/bin/*)'
acctcom acctcom (1) - search and print process accounting
files
activation-client activation-client () - bonobo-
activationdebugging tool
adb adb (1) - general-purpose debugger
<remainder snipped>

> the part that i cant understand is when you run the shell script - i
> could see all the /usr/bin/files output with <whatis> details ,
> with perls everything looks quiet good also but instead of the
> <whatis> details - keeps giving me /usr/bin/filename: nothing
> appropriate.

Again, post a short-but-complete script that generates this output.

> i even tried to write a perl script - used File::Basename

I have no idea what you think File::Basename has to do with this.

> <code>
>
> #!/usr/bin/perl -w
>
> use strict;
> use warnings;
>
> use File::Basename;
>
> my $path = "/usr/bin/";
> my $files = basename($path);
> my $dir = dirname($path);

I still have no idea what you think File::Basename has to do with
this.

> print "dir is $dir , files is $files\n";

Didn't that output tell you you're doing something very wrong? It
should have claimed that $dir is /usr and $files is the empty string.

> system "whatis $path";

Now you're just calling whatis on "/usr/bin/", rather than on all the
files in /usr/bin. Why did you omit the * this time?

Paul Lalli

From: Jim Gibson on
In article <1178039561.065663.196510(a)l77g2000hsb.googlegroups.com>,
Paul Lalli <mritty(a)gmail.com> wrote:

> > > On May 1, 7:22 am, elsiddik <elsid...(a)gmail.com> wrote:
> >
> > > > perl -e "system qw (whatis /usr/bin/*)"
> >
> > > > but its not giving me the same whatislog - what am i doing wrong ?
> >
> > > You are using the qw operator. This operator takes a space-separated
> > > list of barewords and returns a quoted list of words. That is, your
> > > system() call is equivalent to:
> > > system('whatis', '/usr/bin/*');
> >
> > > Change your qw() to qq() or q(), and read up on `perldoc -f system`
> > > for more information.
>
> > well i tried running the code with q and qq but im still getting the
> > same output --
>
> I don't believe you. Please post a short-but-complete script that
> demonstrates this, like so:
>
> $ perl -e'system qq(whatis /usr/bin/*)'
> acctcom acctcom (1) - search and print process accounting
> files
> activation-client activation-client () - bonobo-
> activationdebugging tool
> adb adb (1) - general-purpose debugger
> <remainder snipped>

On my system (Mac OS 10.4.9), "whatis /usr/bin/anything" gives:

/usr/bin/anything: nothing appropriate

I have to do

whatis anything

so "perl -e'system qq(whatis /usr/bin/*)'

give a long list of "nothing appropriate". I can fix this with the Unix
basename utility:

perl -e 'system(qq(whatis `basename /usr/bin/*`));'

>
> > the part that i cant understand is when you run the shell script - i
> > could see all the /usr/bin/files output with <whatis> details ,
> > with perls everything looks quiet good also but instead of the
> > <whatis> details - keeps giving me /usr/bin/filename: nothing
> > appropriate.
>
> Again, post a short-but-complete script that generates this output.
>
> > i even tried to write a perl script - used File::Basename
>
> I have no idea what you think File::Basename has to do with this.

As above.

--
Jim Gibson

Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com