[19053] in Perl-Users-Digest
Perl-Users Digest, Issue: 1248 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jul 5 03:05:43 2001
Date: Thu, 5 Jul 2001 00:05:14 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <994316713-v10-i1248@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 5 Jul 2001 Volume: 10 Number: 1248
Today's topics:
[Q] WHY don't constant and require/do mix? <kj0@mailcity.com>
Re: [Q] WHY don't constant and require/do mix? (Eric Bohlman)
Re: [Q] WHY don't constant and require/do mix? <pne-news-20010705@newton.digitalspace.net>
Re: [Q] WHY don't constant and require/do mix? <pne-news-20010705@newton.digitalspace.net>
Re: [Q] WHY don't constant and require/do mix? <kj0@mailcity.com>
calling a PERL script from Matlab (Steve Miller)
Re: Chmod and File::Find (Tad M) <pne-news-20010705@newton.digitalspace.net>
Re: Chmod and File::Find (Tad M) (Tad McClellan)
Re: Chmod and File::Find (Tad M) (BUCK NAKED1)
Re: Chmod and File::Find (BUCK NAKED1)
Re: clean up an array of references from references whi <uri@sysarch.com>
Re: clean up array from "holes"... <uri@sysarch.com>
Re: executing perl in a browser on win2k server (Chris)
Re: executing perl in a browser on win2k server <wyzelli@yahoo.com>
Re: FAQ 9.4: How do I extract URLs? <qumsieh@sympatico.ca>
Re: FAQ 9.4: How do I extract URLs? <pne-news-20010705@newton.digitalspace.net>
Re: FAQ 9.4: How do I extract URLs? (Tad McClellan)
Re: flash and perl <Deneb.Pettersson@lmf.ericsson.se>
Re: Perl 5.00503 vs. 5.00554 - what's the difference? <pne-news-20010705@newton.digitalspace.net>
Re: Script permissions problem. <pne-news-20010705@newton.digitalspace.net>
Re: Script permissions problem. (Tim Hammerquist)
Re: two changes (Rafael Garcia-Suarez)
Re: web fetching <pne-news-20010704@newton.digitalspace.net>
Re: web fetching (BUCK NAKED1)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 5 Jul 2001 00:05:11 -0400
From: kj0 <kj0@mailcity.com>
Subject: [Q] WHY don't constant and require/do mix?
Message-Id: <9i0p1n$9ie$1@panix3.panix.com>
The following simple scheme does not work as advertised in the
perldocs:
----------------------------------------------------------------
# file "incl.pl";
use constant CUATRO => 4;
1;
----------------------------------------------------------------
#!/usr/local/bin/perl -w
# file C.pl
use strict;
do "incl.pl";
# require "incl.pl";
print(CUATRO . "\n");
1;
----------------------------------------------------------------
>% perl C.pl
CUATRO
>%
----------------------------------------------------------------
Why??
It makes no difference whether "do" or "require" is used; the result
is the same. If the line "do" or "require" line is replaced by the
contents of file incl.pl, then
>% perl C.pl
4
>%
as expected.
KJ
------------------------------
Date: 5 Jul 2001 04:43:43 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: [Q] WHY don't constant and require/do mix?
Message-Id: <9i0r9v$dn5$2@bob.news.rcn.net>
kj0 <kj0@mailcity.com> wrote:
> The following simple scheme does not work as advertised in the
> perldocs:
> ----------------------------------------------------------------
> # file "incl.pl";
> use constant CUATRO => 4;
> 1;
> ----------------------------------------------------------------
> #!/usr/local/bin/perl -w
> # file C.pl
> use strict;
> do "incl.pl";
> # require "incl.pl";
> print(CUATRO . "\n");
> 1;
> ----------------------------------------------------------------
> >% perl C.pl
> CUATRO
> >%
> ----------------------------------------------------------------
> Why??
Try using strict and you'll find that perl complains about CUATRO being a
bareword. The problem is that when perl compiles your main program, it
has no way of knowing that CUATRO is going to be defined as a constant
(actually implemented as a sub) and thus treats it as a bareword literal.
The important thing to remember is that the compilation of your main
program takes places *before* your "do" or "require" are executed, so none
of the code in your included file is going to have any effect on it.
If you put your "do" or "require" in a BEGIN {} block, you should get the
results you wanted, because that will force the inclusion to happen during
compilation.
------------------------------
Date: Thu, 05 Jul 2001 07:02:12 +0200
From: Philip Newton <pne-news-20010705@newton.digitalspace.net>
Subject: Re: [Q] WHY don't constant and require/do mix?
Message-Id: <j2t7ktcs3rpqhc2lqeg0g3upifidgi4g6k@4ax.com>
On 5 Jul 2001 00:05:11 -0400, kj0 <kj0@mailcity.com> wrote:
> Why??
Because the "constant" (actually a subroutine returning a constant value
that 'use constant' constructed for you) has to be visible at compile
time for Perl to know it's a subroutine and not a bareword. If you had
put the constant into a module which you then 'use' (which happens at
compile time rather than runtime), it should work; similarly if you
write &CUATRO or CUATRO() to tell Perl it's a subroutine.
Cheers,
Philip
--
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.
------------------------------
Date: Thu, 05 Jul 2001 07:08:04 +0200
From: Philip Newton <pne-news-20010705@newton.digitalspace.net>
Subject: Re: [Q] WHY don't constant and require/do mix?
Message-Id: <5ct7ktglamcmmbs14ouhgbjra4nin9ioa7@4ax.com>
On 5 Jul 2001 04:43:43 GMT, ebohlman@omsdev.com (Eric Bohlman) wrote:
> Try using strict and you'll find that perl complains about CUATRO being a
> bareword.
No; you try using strict and you'll find that perl doesn't complain
about CUATRO being a bareword. At least not on the 5.005_03 I have here,
nor on a 5.7.0 I have elsewhere.
Can someone tell me why not?
Cheers,
Philip
--
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.
------------------------------
Date: 5 Jul 2001 01:57:02 -0400
From: kj0 <kj0@mailcity.com>
Subject: Re: [Q] WHY don't constant and require/do mix?
Message-Id: <9i0vje$qbo$1@panix3.panix.com>
In <j2t7ktcs3rpqhc2lqeg0g3upifidgi4g6k@4ax.com> Philip Newton <pne-news-20010705@newton.digitalspace.net> writes:
>On 5 Jul 2001 00:05:11 -0400, kj0 <kj0@mailcity.com> wrote:
>> Why??
>Because the "constant" (actually a subroutine returning a constant value
>that 'use constant' constructed for you) has to be visible at compile
>time for Perl to know it's a subroutine and not a bareword.
Thank you, that's very helpful. But there's one thing that's still
puzzling, if one looks at inheritance:
------------------------------------------------------------
# file incl.pl
use constant CUATRO => 4;
1;
------------------------------------------------------------
# file A.pm
package A;
BEGIN {
require "include.pl"; # require works here
}
use strict;
sub talk() { print(CUATRO."\n"); }
sub new {
my $class = shift;
my $self = {};
bless $self, $class;
}
1;
------------------------------------------------------------
# file B.pm
package B;
BEGIN {
do "include.pl"; # require does not work here
}
use strict;
use A;
@B::ISA = ('A');
sub speak() { print(CUATRO."\n"); }
1;
------------------------------------------------------------
#!/usr/local/bin/perl -w
use strict;
use A;
use B;
my $a = new A();
$a->talk();
my $b = new B();
$b->speak();
1;
------------------------------------------------------------
>% C.pl
4
4
>%
But, if the definitions of B is changed slightly, by replacing the
"do" statement in the BEGIN block by a "require" statement, then
>% C.pl
4
CUATRO
>%
I.e. "require" works in the case of A.pm but does not work in the case
of B.pm. What's up with that?
KJ
------------------------------
Date: 4 Jul 2001 23:51:29 -0700
From: steveaux@my-deja.com (Steve Miller)
Subject: calling a PERL script from Matlab
Message-Id: <12db7b5d.0107042251.39066df1@posting.google.com>
Hi!
This SEEMS like something one should be able to do....
Background: I need to get Windows (NT and 98) to split a file for
further processing by Matlab. On Unix, I just shell out and call
split.
I have a perl script that emulates the Unix command of the same name.
I'd
like to shell out from Matlab (in Windows) and split the file, but I
don't
know the first thing about PERL. The first part of the script follows
my signature. (I can send the whole thing if reequested.) What happens
is:
» !perl split.pl -4800000 hnk.bin hnk
Can't locate strict.pm in @INC at split.pl line 12.
BEGIN failed--compilation aborted at split.pl line 12.
AFAIK, I have only the PERL that is included with Matlab on my
machine.
Am I calling this correctly? Are there other things I need to
download?
Is there a better way to do this that I don't know about?
Thanks!
Steve
***
#!/usr/bin/env perl
#
# split -- split a file into pieces
#
# Rich Lafferty <rich@alcor.concordia.ca>
# Sat Mar 6 22:27:28 EST 1999
#
# Perl Power Tools -- http://language.perl.com/ppt/
#
$^W = 1; # -w
use strict;
use Getopt::Std;
use File::Basename;
my $me = basename($0);
------------------------------
Date: Thu, 05 Jul 2001 07:02:11 +0200
From: Philip Newton <pne-news-20010705@newton.digitalspace.net>
Subject: Re: Chmod and File::Find (Tad M)
Message-Id: <ois7kt00iousrrpk3qbbnvdf02m4h25i3q@4ax.com>
On Wed, 4 Jul 2001 16:10:37 -0500 (CDT), dennis100@webtv.net (BUCK
NAKED1) wrote:
> Thanks alot for your suggestions. I'm still not sure what "return" does.
It returns from the find subroutine without executing the rest of it.
perldoc -f return.
> find sub {
> -f or return;
> my $new = s/\`| |\~|\'|\"|\^|\#|\@|\$|\+|\=|\,//g;
> rename $_, $new or print "Could not delete illegal chars: $!<BR>\n";
> },
> $tmpdir ;
You should probably check that the replacement actually replaces
something, or you'll rename lots of files to themselves. Also, if you
are throwing out single characters, consider using tr/` ~'"^#@$+=,//d
instead. Oh, and while you're at it, consider specifying the legal
characters rather than the illegal ones -- for example, if you want only
letters, numbers, hyphens, dots, and underscores, something like
tr/a-zA-Z0-9_.-//cd should do what you want. Then you don't have to
think of every "illegal" character you don't like and risk missing some.
Note that all your examples will change files in $tmpdir *and
directories underneath $tmpdir*.
The rest look good to me.
> Hope everyone's having a great 4th!
Why? What's special about the 4th? <grin>
Cheers,
Phi "not everyone lives in the USA" lip
--
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.
------------------------------
Date: Thu, 5 Jul 2001 00:33:49 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Chmod and File::Find (Tad M)
Message-Id: <slrn9k7rhc.f89.tadmc@tadmc26.august.net>
BUCK NAKED1 <dennis100@webtv.net> wrote:
> Subject: Chmod and File::Find (Tad M)
Please don't launch new threads about the same thing.
Please post as followups with a References: header, so news
software will work right.
Please do not write to a particular person here. You are writing
to a newsgroup. If you had been writing to a particular person,
you would be using email instead of news.
If you post a followup to one of my postings, I will very likely
see it. If you start an unrelated thread, I might see it and I
might not.
>I'm still not sure what "return" does.
What have you done about that?
Have you looked up the docs for that function?
perldoc -f return
Since it has to do with subroutines, then another place to
try might be:
perldoc perlsub
>Anyway, how'd I do?
Very poorly I'm afraid.
Have you run this code?
You should try stuff out before you post it here. I hope you
have been trying out the suggestions you get here.
1) it does not work!
All the other problems are moot compared to this one. Seems
you should have been able to answer your question above
after trying it.
Did you try running this code? Did it work?
2) you have a bazillion backslashes that a maintenance programmer
must mentally filter out. Most of them are not needed at all.
3) alternations of a bunch of single characters can be done
_much_ more efficiently with a character class or better
yet, tr///.
4) your code formatting *still* sucks!
(Is your news SW screwing it up, or do you really see it that way?)
5) $new is going to *always* be a number. And the "new" name is
in the $_ variable NOT in the $new variable. Sheesh!
5a) so you are trying to move _from_ the _new_ name, but it
does not exist. The rename() must fail.
All of this would have become quite clear if you could have
been bothered to run the code with:
print "rename $_, $new\n";
before asking thousands of other people to help.
I get the distinct feeling that you are having us do your
work for you. This is not a good feeling.
Did you try running this code? Did it work?
6) you can "lose" files with your code. I hope you have good
backups of your working directories:
foo^bar= and foo"bar' will _both_ be renamed to foobar
one lives on, one goes to bit heaven...
7) your subroutine is getting rather longish for an anon sub.
I suggest a named sub for easier maintenance.
>use File::Find;
>
># Delete illegal characters and spaces in filename in $tmpdir
>
>find sub {
>-f or return;
>my $new = s/\`| |\~|\'|\"|\^|\#|\@|\$|\+|\=|\,//g;
>rename $_, $new or print "Could not delete illegal chars: $!<BR>\n";
> },
>$tmpdir ;
What is that <BR> for? This makes me suspect that you are using
Perl for a CGI application.
That, in turn, makes me suspicious of where the value of $tmpdir
came from.
Where does the value of $tmpdir come from?
># Change all .exe files in $tmpdir to .exe.txt and chmod to 644
>
>find sub {
>-f or return;
>if ( (my $new = $_) =~ s/\.exe$/\.exe\.txt/ig ) {
^ ^
^ ^ more useless backslashes
Now here you got the copying right. Why not above?
Did you know that you will be forcing
foo.EXE => foo.exe.txt
??
That will be a big problem if you also have a foo.exe file
one lives on, one goes to bit heaven...
I really hope you have recent backups. :-)
Try running this code:
--------------------------------------------
#!/usr/bin/perl -w
use strict;
use File::Find;
my $tmpdir = 'testdir';
find \&bad_chars, $tmpdir;
sub bad_chars {
return unless -f; # process only plain files
# only rename() if "bad" characters found in filename
my $new = $_;
# return unless $new =~ s/`| |~|'|"|\^|#|@|\$|\+|=|,//g; # less backslashes
# return unless $new =~ s/[` ~'"^#@\$+=,]//g; # character class
# return unless $new =~ tr/` ~'"^#@$\+=,//d; # transliterate
return unless $new =~ s/[^\w.-]//g; # list the chars allowed instead
# of disallowed
if ( -e $new ) {
print "file '$new' already exists!<BR>\n";
}
else {
rename $_, $new or print "Could not delete chars from '$_': $!<BR>\n";
}
}
--------------------------------------------
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 5 Jul 2001 01:11:16 -0500 (CDT)
From: dennis100@webtv.net (BUCK NAKED1)
Subject: Re: Chmod and File::Find (Tad M)
Message-Id: <4304-3B440504-171@storefull-245.iap.bryant.webtv.net>
I added a sub to change index.blah to main.blah, and a sub to delete any
htaccess or htpasswd file. Here's what I ended up with...
# fix the files in $tmpdir
find \&fix_temp_files, $tmpdir;
sub fix_temp_files {
my $file = $_;
# skip anything but a plain file
return unless -f $file;
# now do the work
del_htaccess($file);
rename_index($file);
fix_perms($file);
fix_illegal_chars($file);
textify_exes($file);
}
sub del_htaccess {
my ($file) = @_;
my $newname = $file;
return unless $newname =~ m/\.htaccess|\.htpasswd$/i;
unlink($newname);
}
sub rename_index {
my ($file) = @_;
my $newname = $file;
return unless $newname =~ s/\index/main/i;
safe_rename($file, $newname);
}
sub fix_perms {
my ($file) = @_;
chmod 0644, $file or
handle_error($file,"couldn't chmod to 0644",$!);
}
sub fix_illegal_chars {
my ($file) = @_;
my $newname = $file;
return unless $newname =~ tr/-._A-Za-z0-9/_/c;
safe_rename($file, $newname);
}
sub textify_exes {
my ($file) = @_;
my $newname = $file;
return unless $newname =~ s/\.exe$/.exe.txt/i;
safe_rename($file, $newname);
}
sub safe_rename {
my ($oldfile, $newfile) = @_;
return if ($oldfile eq $newfile);
if (-f $newfile) {
handle_error($oldfile,"file " . $newfile ." already
exists");
return;
}
rename $oldfile, $newfile or
handle_error($oldfile,"couldn't rename to ".$newfile,$!);
}
sub handle_error {
my ($file, $message, $syserror) = @_;
print "$file: <b>$message</b>";
print " ($syserror)" if $syserror;
print "<br>\n";
}
I hope that does it. No, I'm not trying to push work off on anyone. I
spent much time on this. I just needed some help. Thanks to all...
especially for explaining to me why I was clobbering files.
I made a new subject because I thought I should've included File::Find
in the subject. Sorry about bad wrap and no quoting; but that's a fault
of my OS, WTV.
Regards,
Dennis
------------------------------
Date: Thu, 5 Jul 2001 01:18:14 -0500 (CDT)
From: dennis100@webtv.net (BUCK NAKED1)
Subject: Re: Chmod and File::Find
Message-Id: <4303-3B4406A6-469@storefull-245.iap.bryant.webtv.net>
JFYI... Tad: I have been taking advice and testing it. After someone
suggested checking return values, I did that, cleaned it up to where I
didn't get any errors, and then I posted it.
Regards,
--Dennis
------------------------------
Date: Thu, 05 Jul 2001 04:07:19 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: clean up an array of references from references which are pointing into empty arrays
Message-Id: <x7elrw5894.fsf@home.sysarch.com>
>>>>> "A" == Alexvalara <alexvalara@aol.com> writes:
A> the problem now is that having an array of arrays you want to get
A> rid of empty arrays of the array! For example, you have something
A> like @a=(\@b,\@c,\@d...) where \@c=("") and you want to come up
A> with an arrayof the following form (\@b,\@d...).
well, you learned quickly enough to ignore moronzilla.
forst, do you mean emtpy arrays, or ones that actually have only "" as
the first element?
in either case, the concept of removing elements of an array based on
some criterion, should trigger the grep function. it is expressly meant
for this use.
so, for deleting all empty arrays from a LoL:
@non_empty = grep { @{$_} } @mixed ;
so, for deleting all arrays which have a null string in the first entry
in a LoL:
@non_empty = grep { length $_->[0] } @mixed ;
that assumes ALL entries in the main array are array refs. you can
insert another test to make sure you have an array ref before checking
the first entry for its length.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Learn Advanced Object Oriented Perl from Damian Conway - Boston, July 10-11
Class and Registration info: http://www.sysarch.com/perl/OOP_class.html
------------------------------
Date: Thu, 05 Jul 2001 03:59:25 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: clean up array from "holes"...
Message-Id: <x7hews58ma.fsf@home.sysarch.com>
>>>>> "AS" == Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> writes:
AS> According to Uri Guttman <uri@sysarch.com>:
>> >>>>> "TM" == Tom Melly <tom.melly@ccl.com> writes:
>>
TM> @array = ("", "hello", "", "goodbye");
TM> foreach(@array){
TM> push @array2, $_ if $_;
TM> }
TM> @array = @array2;
>>
>> that is what grep is for:
>>
>> @array = grep $_, @array ;
AS> That fails to convey "0".
i am well aware of that. but the given data was words or null strings so
that is what i went with.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Learn Advanced Object Oriented Perl from Damian Conway - Boston, July 10-11
Class and Registration info: http://www.sysarch.com/perl/OOP_class.html
------------------------------
Date: 4 Jul 2001 23:30:28 -0700
From: chris@wmccmsvr.ssr.hp.com (Chris)
Subject: Re: executing perl in a browser on win2k server
Message-Id: <ab9571e4.0107042230.47b9b12d@posting.google.com>
I quickly realized after my original post that it wasn't a perl
problem, and I've since decided that it isn't a client-side issue
either, thanks to some of you guys' help and a little more research in
non-perl-related groups. I think the problem lies in the user
permissions on the server. I read somewhere that in a windows
environment the cgi scripts have to be specified as a user to access
the ODBC (notice the exasperation when it comes to database files,
like I said earlier). So I'm in the wrong group, but I still have a
somewhat pertinent question, in case some of you have dealt with this
sort of thing before: why exactly does the cgi script have to be set
up like a user? I'm new at running perl on a windows box.
------------------------------
Date: Thu, 5 Jul 2001 16:18:16 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: executing perl in a browser on win2k server
Message-Id: <J%T07.2$N13.392@vic.nntp.telstra.net>
"Chris" <chris@wmccmsvr.ssr.hp.com> wrote in message
news:ab9571e4.0107042230.47b9b12d@posting.google.com...
> I quickly realized after my original post that it wasn't a perl
> problem, and I've since decided that it isn't a client-side issue
> either, thanks to some of you guys' help and a little more research in
> non-perl-related groups. I think the problem lies in the user
> permissions on the server. I read somewhere that in a windows
> environment the cgi scripts have to be specified as a user to access
> the ODBC (notice the exasperation when it comes to database files,
> like I said earlier). So I'm in the wrong group, but I still have a
> somewhat pertinent question, in case some of you have dealt with this
> sort of thing before: why exactly does the cgi script have to be set
> up like a user? I'm new at running perl on a windows box.
Because the cgi scripts inherits the permissions of the entity which runs
it, in this case the web-server which normally runs on the system as a user
with very low (read 'no') privileges.
Typically on IIS systems this user is called !USR_servername or similar.
Adding this user to the appropriate group with database permissions may
help. Or even giving it explicit additional permissions.
Wyzelli
--
push@x,$_ for(a..z);push@x,' ';
@z='092018192600131419070417261504171126070002100417'=~/(..)/g;
foreach $y(@z){$_.=$x[$y]}y/jp/JP/;print;
------------------------------
Date: Thu, 5 Jul 2001 00:35:09 -0400
From: "Ala Qumsieh" <qumsieh@sympatico.ca>
Subject: Re: FAQ 9.4: How do I extract URLs?
Message-Id: <A2S07.19462$g92.2695245@news20.bellglobal.com>
"BUCK NAKED1" <dennis100@webtv.net> wrote in message
news:14600-3B43DBAD-532@storefull-247.iap.bryant.webtv.net...
> I've read that example several times and still don't get it. Can someone
> please explain where you put the URL to grab into that qx script? And
> where do you put the location to store it in?
Here is the example again:
print "$2\n" while m{
< \s*
A \s+ HREF \s* = \s* (["']) (.*?) \1
\s* >
}gsix;
This could be re-written as:
while (m{
< \s*
A \s+ HREF \s* = \s* (["']) (.*?) \1
\s* >
}gsix) {
print "$2\n";
}
The m// (or should I say m{}) matches against $_ since no other variable is
explicitly specified. The regexp basically matches strings of the form:
<A HREF= 'http://www.perl.com' >
- white space is optional except between A and HREF.
- single quotes can be double quotes, but they opening and closing quotes
have to match.
- Whatever is between the quotes is saved into $2.
Each iteration of the while loop matches the next URL in the string and
prints it, until no more matches occur.
HTH,
--Ala
------------------------------
Date: Thu, 05 Jul 2001 07:09:48 +0200
From: Philip Newton <pne-news-20010705@newton.digitalspace.net>
Subject: Re: FAQ 9.4: How do I extract URLs?
Message-Id: <uit7ktg3g5272bjii6fefb2c1sonfnj22c@4ax.com>
On Wed, 4 Jul 2001 22:14:53 -0500 (CDT), dennis100@webtv.net (BUCK
NAKED1) wrote:
> I've read that example several times and still don't get it. Can someone
> please explain where you put the URL to grab into that qx script? And
> where do you put the location to store it in?
It doesn't fetch anything from anywhere, in case you thought that. It
goes through a string that contains HTML looking for things that look
like hyperlinks, and extracts the hyperlink target from and prints it.
Cheers,
Philip
--
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.
------------------------------
Date: Wed, 4 Jul 2001 23:14:06 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: FAQ 9.4: How do I extract URLs?
Message-Id: <slrn9k7mru.f1r.tadmc@tadmc26.august.net>
BUCK NAKED1 <dennis100@webtv.net> wrote:
>I've read that example several times and still don't get it.
Perhaps it does not answer the question that you think it answers.
You have been asking about fetching web pages a lot lately.
That FAQ answer does not have _anything_ to do with fetching web pages!
>Can someone
>please explain where you put the URL to grab into that qx script?
The code there extracts URLs from HTML data. Where the HTML data
came from is not addressed there. It could be a local file, or
typed into your source code, of fetched with LWP::Simple.
You appear to be confused about the distinction between a URL,
and the Uniform Reference that it Locates.
URLs are little strings that say where a web resource is located.
web pages are gobs of HTML stuff.
URLs tell you where to get web pages. URLs are not themselves
web pages.
>And
>where do you put the location to store it in?
You put the web page (HTML) in $_.
The code prints the URLs that it finds embedded in that HTML.
If you want to do something other than print them, then you modify
the code so that it does something other than print them.
But my guess is that this FAQ does not apply to what you want to do...
What _do_ you want to do?
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 05 Jul 2001 09:08:32 +0300
From: Deneb Pettersson <Deneb.Pettersson@lmf.ericsson.se>
Subject: Re: flash and perl
Message-Id: <3B440460.DEF11AC8@lmf.ericsson.se>
ok, the flash was jsut a thought, i was just wondering on wehterit is
possible, i don't really need anything fancy, but a way of doing the swf
dynamically depending on people's choices. I know pretty well what i can do
with perl in ways of handling my data and files, it's jsut the output into
swf as an option that was intriguing... and
http://2shortplanks.com/flash/
seems to be the answer, but it hasn't been updated for a while, i'll just
have to see what i can do with it....when i finally find the tim, that
is....
Malte Ubl wrote:
> Deneb Pettersson schrieb:
> >
> > hi there, i'm doing a perl script atm which makes up a text form given
> > variables, and at some point i will also have a picture catalogue with
> > pictures corresponding to the different options, so that once you have
> > chosen and press enter you will get a slideshop with your options....
> > this is nice, but then i jsut realised, that if it is possible to do
> > this into a flash then it would be alot cooler....
>
> Take a look at Flash Generator. Then when you get so far that you ask
> yourself which data source to use, take a look at Perl again.
>
> Bye,
> ->malte
------------------------------
Date: Thu, 05 Jul 2001 07:02:02 +0200
From: Philip Newton <pne-news-20010705@newton.digitalspace.net>
Subject: Re: Perl 5.00503 vs. 5.00554 - what's the difference?
Message-Id: <u4s7ktks06cm1b3ua55jdjmh4ai4thqgpu@4ax.com>
On 4 Jul 2001 12:01:22 -0700, paul@margalo.com (Paul Laub) wrote:
> Dear all,
>
> I just noticed that for pretty printing data structures, 5.00554
> relies on dumpvar.pl whereas 5.00503 uses Dumpvalue.pm. This is
> perplexing as 5.00554 is a higher version number than 5.00503 yet
> Dumpvalue.pm appears to be an updated, modularized version of the old
> dumpvar.pl.
Can't tell you the exact reason, but 5.005_54 is not really "higher"
than 5.005_03. Back then, _ numbers over 50 were development releases
and _ numbers under 50 were "real" releases. So 5.005_03 is a release
version while 5.005_54 is a development version that might have some new
stuff in it but might also be a bit more unstable. It might have come
before 5.005_54 (perhaps it was part of the development from 5.005_01 to
5.005_02, for example).
Cheers,
Philip
--
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.
------------------------------
Date: Thu, 05 Jul 2001 07:03:16 +0200
From: Philip Newton <pne-news-20010705@newton.digitalspace.net>
Subject: Re: Script permissions problem.
Message-Id: <r6t7ktcmiggjmgi8n0hq5idblgmduf8b1p@4ax.com>
[Don't followup-to comp.lang.perl; that group doesn't exist.]
On Wed, 4 Jul 2001 20:40:38 +0100, Matt L. <mlaw@talk21.comNOSPAM>
wrote:
> The script is failing with 'permission denied' in the error log.
> What exactly should the images directory permissions be set to
> for this to work properly?
The user under which the script is run (often 'nobody' or whatever the
web server runs as, unless you have a wrapper) needs write permission,
the 'w' bit for either that user or his group has to be on.
> #!/usr/bin/perl -wT
> use CGI qw/:standard/;
> print header,
> start_html('file upload'),
> $file = param('file');
> open (SAVE, ">../images/$file") || die $!;
In a CGI environment, you can't rely on the current directory. It might
be the same directory as the one the script is in or anywhere else. Use
a full path here instead of one relative to the current directory.
Oh, and this looks as if $file is a filename...
> while (<$file>) {
> print SAVE $_;
> }
...but you're treating it as a file *handle* here. Strange. And if
you're really using image files (which are presumably binary, not
text-based), then reading line-by-line makes little sense as well, since
images won't have meaningful "lines". Better to use read().
Cheers,
Philip
--
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.
------------------------------
Date: Thu, 05 Jul 2001 06:36:13 GMT
From: tim@vegeta.ath.cx (Tim Hammerquist)
Subject: Re: Script permissions problem.
Message-Id: <slrn9k83cu.22v.tim@vegeta.ath.cx>
Philip Newton <pne-news-20010705@newton.digitalspace.net> wrote:
> [Don't followup-to comp.lang.perl; that group doesn't exist.]
Don't tell the frequenters of comp.lang.perl that! They post quote
frequently as if they exist. When someone tells them they don't exist,
they get quite indignant.
While I realize that comp.lang.perl has "officially" been replaced by
comp.lang.perl.*, many people remain in clp and refuse to even lurk in
clpm.
I've actually seriously wondered, is there any harm in continuing to
answer posts in clp?
--
-Tim Hammerquist <timmy@cpan.org>
If history teaches us anything, it's that everyone will be part
of the problem, but not everyone will be part of the solution.
-- Larry Wall
------------------------------
Date: 5 Jul 2001 06:40:39 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: two changes
Message-Id: <slrn9k82vp.q5r.rgarciasuarez@rafael.kazibao.net>
Philip Newton wrote in comp.lang.perl.misc:
}
} Well, sort of; on one shell account I have, /usr/bin/perl and
} /usr/local/bin/perl *both* exist, but one's the system-supplied 5.004,
} and the other is a hand-compiled 5.005_03. I'd prefer the 5.005_03 that
} the administrators compiled (since it's newer). Symlinking doesn't
} really help here, since both versions can't share the same pathname, but
} they presumably had their reason for not completely replacing the
} existing /usr/bin/perl.
Weird setups exist: on one of the machines I administrate, (a Solaris 8
server), there is a /usr/bin/perl and a /usr/local/bin/perl, both
version 5.005_03. But /usr/bin/perl is vendor-supplied and compiled with
Sun's cc ; /usr/local/bin/perl is compiled with gcc. That's because
MySQL had to be compiled with gcc and the perl interpreter required to
be compiled with the same C compiler in order to accept DBD::mysql.
--
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
------------------------------
Date: Thu, 05 Jul 2001 06:40:13 +0200
From: Philip Newton <pne-news-20010704@newton.digitalspace.net>
Subject: Re: web fetching
Message-Id: <qpq7ktsiunmb4farcrnem1ujjst8g490gq@4ax.com>
On Wed, 4 Jul 2001 17:14:16 -0500 (CDT), dennis100@webtv.net (BUCK
NAKED1) wrote:
> That's true that you can put modules in a local directory. However,
> sometimes they need to be compiled.
That's true. And if you have no shell access to a compiler, and no
similar system to compile the module on previously, you have a problem.
> Is there anything from the standard perl distribution that will allow
> you to grab and store a file from the web?
Not by itself, but it gives you the tools. Just like there's nothing in
the standard perl distribution which will search a file for a pattern
and print out all matching lines, but you can rig your own with
while(<>), regular expressions, if, and print.
> I have Socket.pm installed on my server; but not Socket::INET. You seem
> to be saying that Socket will grab a file.
No, but Socket will help you with some of the stuff you need to open a
socket. Once you've opened a socket to another system's port 80, you can
speak HTTP over that socket and interpret the response. For example, if
you 'GET /index.html HTTP/1.0' and the server answers with a 200
response, you can take the server's response (minux the HTTP headers)
and store it into a file.
It'll be more work than if you had LWP::Simple, and you'd have to know
the HTT protocol.
By the way, I was talking about IO::Socket::INET, not Socket::INET.
Hrrm, `perldoc perlipc` says that "IO::Socket is included as part of the
standard Perl distribution as of the 5.004 release". So unless you have
an ancient version of Perl, you probably do have IO::Socket and
IO::Socket::INET.
> I didn't know that you could
> grab a file off the internet by just using the plain Socket.pm.
You don't even need Socket.pm as the built-in socket() and connect()
calls can open a socket; Socket.pm simply gives you a couple of useful
routines and constants that will help you use socket(). Then, you can do
whatever you can do with sockets -- for example, request a document via
HTTP. Or have an FTP session. Or send mail via SMTP. Or speak to a
database that communicates via TCP/IP or Unix domain sockets (if you can
"speak" the database protocol).
> Could you give me some code on how to do that? I'd appreciate it.
Have a look at `perldoc perlipc`, specifically the section "Sockets:
Client/Server Communication". There's a sample TCP client in the
subsection "Internet TCP Clients and Servers" which uses only basic Perl
and Socket.pm. Of course, you'd need to beef that up by printing an HTTP
request to the socket before reading from it.
There's also a section on "TCP Clients with IO::Socket" and "A Webget
Client" which you could read, as you should have IO::Socket standard
with your Perl (as I said above). Note that the example only sends a
line containing a GET request; some servers also require a "Host:" HTTP
header, especially if they have virtual hosting. But it has something to
start you off with.
However, doing it this way would probably be quite a bit of work. It's
maybe educational to write your own program, but if you can, I'd
recommend trying to go with libwww-perl anyway. Still, the above has the
building blocks you need if you really want to do it yourself.
Cheers,
Philip
--
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.
------------------------------
Date: Thu, 5 Jul 2001 01:25:37 -0500 (CDT)
From: dennis100@webtv.net (BUCK NAKED1)
Subject: Re: web fetching
Message-Id: <4303-3B440861-470@storefull-245.iap.bryant.webtv.net>
Thanks for that excellent explanation. I mistated. I have Socket.pm and
IO::Socket installed; but not IO::Socket::INET.
Regards,
--Dennis
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 1248
***************************************