On Sat, Oct 2, 2010 at 11:40 AM, "jobst müller" <floo...@web.de> wrote:
> Hello Alex
>
> many thanks for the answer.
>
> well i put all to home > usr > perl

/home/usr is a pretty strange path. Typically, the subdirectories of
/home represent individual users' "home directory". For example,
/home/jmüller, or /home/bmccaig. When each user logs into a Linux
system, they typically start in their home directory.

Now it's possible that you've named your user account usr. I'm not
here to judge. ;) I'm just saying that it's a little confusing,
considering the meaning of /usr. So I wonder if maybe it's a spelling
mistake or something.

It also seems strange to store plain HTML files that I expect are Web
site or documentation files in a path containing 'perl'. Again, I'm
not sure exactly what you're doing so maybe it does make sense. It
shouldn't actually matter to Perl where you store the files (in fact,
the original name, html.files was fine), but sensible file system
paths are as important as sensible variable names. :)

> Can't stat /home/usr/perl/htmlfiles: No such file or directory

Your Linux system seems pretty sure that the path you're specifying
doesn't exist. What I would recommend is that you try from a text
terminal first and make sure that the file exists. For example, does
this command work:

file /home/usr/perl/htmlfiles

The file command basically makes an educated guess about what type of
file(s) you've specified. If that directory exists, then the output
should be something like:

/home/usr/perl/htmlfiles: directory

If that path is wrong then you can't expect Perl to do anything useful
with it. :) I noticed that in your first E-mail you specified the path
as 'home/usr/perl/html.files'. Notice how the path doesn't begin with
a forward-slash (/)? Just to make sure you understand, that's a
relative path, which is derived from where you currently are in the
file system. If you are currently in /home/usr, for example, then that
path actually means /home/usr/home/usr/perl/html.files. Obviously not
what you want. It's important to be very precise with these things
because Linux and Perl cannot guess what you mean. :) If you don't
want where you are to affect things, then you need to specify an
absolute path. Absolute paths in unices, such as Linux, always begin
with a forward slash (i.e., /home/usr/perl/htmlfiles). That initial
forward slash is referring to the root of the file system (the very
top level directory).

One option is to pass the path on the command line. I'm not familiar
with OpenSuSe, but I imagine that your shell is probably bash. Using
tab-completion, bash can help you to find the correct path. You can
then pass the path to your Perl script on the command line.

For example:

#!/usr/bin/env perl

use strict;
use warnings;

if(@ARGV != 1)
{
    print STDERR <<EOF;
Usage: $0 path

path: The directory containing the tree of HTML files.
EOF
    exit 1;
}

my ($path) = @ARGV;

print "SUCCESS: The path you specified is '$path'!\n";

__END__

All that this short program does is confirm that exactly one argument
was passed to the script and then it prints it out. If zero or many
arguments were passed instead then it prints an error message and
exits.

If you save it to a file (I saved mine to args.pl) and execute it, you
should see how it works:

$ perl args.pl
Usage: ./args.pl path

path: The directory containing the tree of HTML files.
$ perl args.pl foo
SUCCESS: The path you specified is 'foo'!

Try it out and experiment with tab completion in your shell. You
should be able to let your shell help you to find the correct path
this way. For example, if you type 'perl args.pl /home/' and then
press the tab key twice, you should see a list of possible options
printed. Just keep filling in the path until you find the destination
that you're after. Then, instead of specifying the path in the script,
you can pass it on the command line.

#!/usr/bin/env perl

use strict;
use warnings;

use File::Find::Rule;

# Here we make sure that exactly 1 argument was passed.
# Otherwise, abort.
if(@ARGV != 1)
{
    print STDERR <<EOF;
Usage: $0 path

path: The directory containing the tree of HTML files.
EOF
    exit 1;
}

# Here's the path that you specify on the command line.
my ($path) = @ARGV;

# NOTE: I changed the name argument to accept .htm files as well.
# I expected '*.html?' to work, but it didn't. The regex does, however.

my @files = File::Find::Rule->file()->name(qr{.*\.html?})->in($path);

if(@files)
{
    for my $file (@files)
    {
        print "$file\n";
    }
}
else
{
    print STDERR "No files found...\n";
}

__END__

I have my Web site located at /var/www/localhost/htdocs. If I save
this script as find-html.pl and then pass /var/www/localhost/htdocs
when I execute it, then I get the following results:

$ perl find-html.pl /var/www/localhost/htdocs
/var/www/localhost/htdocs/donate.html
/var/www/localhost/htdocs/downloads.html
/var/www/localhost/htdocs/projects.html
/var/www/localhost/htdocs/about.html
/var/www/localhost/htdocs/contact.html
/var/www/localhost/htdocs/news.html
/var/www/localhost/htdocs/index.html

Looks like a minor success to me. :)

-- 
Brandon McCaig <bamcc...@gmail.com>
V zrna gur orfg jvgu jung V fnl. Vg qbrfa'g nyjnlf fbhaq gung jnl.
Castopulence Software <http://www.castopulence.org/> <bamcc...@castopulence.org>

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to