[17745] in Perl-Users-Digest
Perl-Users Digest, Issue: 5165 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Dec 20 21:05:35 2000
Date: Wed, 20 Dec 2000 18:05:12 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <977364311-v9-i5165@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 20 Dec 2000 Volume: 9 Number: 5165
Today's topics:
Re: "Native" perl way to copy files (Richard Zilavec)
Re: "Native" perl way to copy files <cleon42@my-deja.com>
Re: "Native" perl way to copy files (Abigail)
bug in open() (Brandon Metcalf)
Convert YM to YMD Where D Is Last D of M Using Date::Ma <monty@primenet.com>
Re: Convert YM to YMD Where D Is Last D of M Using Date <jleffler@informix.com>
Re: Convert YM to YMD Where D Is Last D of M Using Date (Abigail)
Re: Directory Recursion Kwestion... (Tom Christiansen)
Re: Directory Recursion Kwestion... <ddunham@redwood.taos.com>
Re: DSN/ODBC Client-Server Problem <abe@ztreet.demon.nl>
Re: DSN/ODBC Client-Server Problem (Abigail)
Re: Executing perl on linux <Juha.Laiho@iki.fi>
Re: How do I use form email <secursrver@hotmail.com>
HTML parse nodo70@my-deja.com
Re: HTML parse <cleon42@my-deja.com>
Re: HTML parse (Jerome O'Neil)
Re: No embeding please! <alex@hoopsie2.com>
ok <alex@hoopsie2.com>
Re: perl DBI <jeff@vpservices.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 20 Dec 2000 23:05:01 GMT
From: rzilavec@tcn.net (Richard Zilavec)
Subject: Re: "Native" perl way to copy files
Message-Id: <3a433b0c.190980600@news.tcn.net>
On Wed, 20 Dec 2000 16:39:47 -0500, "Antoine Beaupre (LMC)"
<lmcabea@lmc.ericsson.se> wrote:
>Hello!
>
>I guess that you can probably copy a file with:
>
> system "cp $file $newfile"
>
>in perl. But this is platform dependent... Is there a "native" way to
>copy files in perl (à la rename)? I searched all the doc I could find
>and couldn't figure it out..
You might want to look at File::Copy.
--
Richard Zilavec
rzilavec@tcn.net
------------------------------
Date: Wed, 20 Dec 2000 23:43:52 GMT
From: Adam Levenstein <cleon42@my-deja.com>
Subject: Re: "Native" perl way to copy files
Message-Id: <91rg7m$uq5$1@nnrp1.deja.com>
One (albeit slow) way would be this:
open(a, "file1.txt");
open(b, "> file2.txt");
while (<a>) {
print b $_;
}
close(a);
close(b);
Just a thought - it's the "quick 'n dirty" way, but it does work. The
problem is that if you're looking for efficiency, this is not the way
to go. But on the upside, it is platform independent. :)
Adam
In article <3A412723.D99788C2@lmc.ericsson.se>,
"Antoine Beaupre (LMC)" <lmcabea@lmc.ericsson.se> wrote:
> Hello!
>
> I guess that you can probably copy a file with:
>
> system "cp $file $newfile"
>
> in perl. But this is platform dependent... Is there a "native" way to
> copy files in perl (à la rename)? I searched all the doc I could find
> and couldn't figure it out..
>
> Thanks
>
> A.
>
--
-------------------------------------------------
Adam Levenstein
cleon42@my-deja.com
"Extraordinary claims require extraordinary evidence."
-- Carl Sagan
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: 21 Dec 2000 00:50:41 GMT
From: abigail@foad.org (Abigail)
Subject: Re: "Native" perl way to copy files
Message-Id: <slrn942kv1.la8.abigail@tsathoggua.rlyeh.net>
Antoine Beaupre (LMC) (lmcabea@lmc.ericsson.se) wrote on MMDCLXVIII
September MCMXCIII in <URL:news:3A412723.D99788C2@lmc.ericsson.se>:
~~ Hello!
~~
~~ I guess that you can probably copy a file with:
~~
~~ system "cp $file $newfile"
~~
~~ in perl. But this is platform dependent... Is there a "native" way to
~~ copy files in perl (à la rename)? I searched all the doc I could find
~~ and couldn't figure it out..
If you mean "primitive" when you say "native", then the answer is no.
In many aspects, Perl closely follows the Unix/C way, with only a wafer
thin layer of itself. This includes most of the functions dealing with
files and directories.
There's no Unix primitive for copy, and hence, there's no such primitive
in Perl.
(Now, one could argue that Perl is there for programmers convenience,
and for that reason alone, a copy function belongs in Perl. I think that
if Larry had put copy in Perl in perl1 or perl2, that an RFC to drop it
from the core for perl6 wouldn't have made much chance. But, it's not in
Perl. There is however a module called 'File::Copy').
Abigail
--
perl -we 'print q{print q{print q{print q{print q{print q{print q{print q{print
qq{Just Another Perl Hacker\n}}}}}}}}}' |\
perl -w | perl -w | perl -w | perl -w | perl -w | perl -w | perl -w | perl -w
------------------------------
Date: 21 Dec 2000 01:51:10 GMT
From: bmetcalf@nortelnetworks.com (Brandon Metcalf)
Subject: bug in open()
Message-Id: <91rnme$hvu$1@bcarh8ab.ca.nortel.com>
open() seems to have been broken in Perl 5.005_3 as well as the latest
ActivePerl. In Perl 5.6.0 on solaris open() behaves as it should.
Can anyone confirm this?
$ cat ~/tmp/jj
open (DD, "lls|") || die "bad command: $!";
while (<DD>) { print $_ }
print "shouldn't get here\n";
$ ./perl -v
This is perl, v5.6.0 built for sun4-solaris
$ ./perl -wMstrict ~/tmp/jj
Can't exec "lls": No such file or directory at /bnw/home/bmetcalf/tmp/jj
line 1.
bad command: No such file or directory at /bnw/home/bmetcalf/tmp/jj line
1.
$ perl -v ~/tmp/jj
This is perl, version 5.005_03 built for sun4-solaris
$ perl -wMstrict ~/tmp/jj
Can't exec "lls": No such file or directory at /bnw/home/bmetcalf/tmp/jj
line 1.
shouldn't get here
Thanks,
Brandon
------------------------------
Date: 21 Dec 2000 01:15:44 GMT
From: Jim Monty <monty@primenet.com>
Subject: Convert YM to YMD Where D Is Last D of M Using Date::Manip
Message-Id: <91rlk0$3kc$1@nnrp2.phx.gblx.net>
I want to use Date::Manip to convert date strings from YYYYMM to
YYYYMMDD, where the DD is the last day of the month MM. How do I
do this?
The Date::Manip man page is over 2,600 lines long and grepping it
like a madman didn't help me, so I'm looking for a good spoon
feeding here. I promise to pay the USENET community back. Thank you.
--
Jim Monty
monty@primenet.com
Tempe, Arizona USA
------------------------------
Date: Thu, 21 Dec 2000 01:21:04 GMT
From: Jonathan Leffler <jleffler@informix.com>
Subject: Re: Convert YM to YMD Where D Is Last D of M Using Date::Manip
Message-Id: <3A415AE1.BBDF299@informix.com>
Jim Monty wrote:
> I want to use Date::Manip to convert date strings from YYYYMM to
> YYYYMMDD, where the DD is the last day of the month MM. How do I
> do this?
>
> The Date::Manip man page is over 2,600 lines long and grepping it
> like a madman didn't help me, so I'm looking for a good spoon
> feeding here. I promise to pay the USENET community back. Thank you.
use Date::Manip;
my $date = &ParseDate("last day of June 1992");
print "$date\n";
reveals:
1992063000:00:00
However, I didn't immediately find a way to use pure numbers in place of
"June 1992"; neither 199206 nor 1992-06 worked. However, if you care to
work the YYYYMM into a month name and a year, then ParseDate seems
likely to do the job:
use Date::Manip;
my @months = ("", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul",
"Aug", "Sep", "Oct", "Nov", "Dec");
my $yyyymm = "199206";
my $yyyy = substr $yyyymm, 0, 4;
my $mm = substr $yyyymm, 4;
my $date = &ParseDate("last day of $months[$mm] $yyyy");
print "$date\n";
I only scanned 'perldoc Date::Manip' as far as the example at the top of
page 5 of the Date::Manip manual, and took a flying guess:
$date=&ParseDate("1st thursday in June 1992");
Maybe grep is too blunt a tool and a little reading will help.
--
Yours,
Jonathan Leffler (Jonathan.Leffler@Informix.com) #include <disclaimer.h>
Guardian of DBD::Informix v1.00.PC1 -- http://www.perl.com/CPAN
"I don't suffer from insanity; I enjoy every minute of it!"
------------------------------
Date: 21 Dec 2000 01:28:57 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Convert YM to YMD Where D Is Last D of M Using Date::Manip
Message-Id: <slrn942n6p.la8.abigail@tsathoggua.rlyeh.net>
Jim Monty (monty@primenet.com) wrote on MMDCLXIX September MCMXCIII in
<URL:news:91rlk0$3kc$1@nnrp2.phx.gblx.net>:
;; I want to use Date::Manip to convert date strings from YYYYMM to
;; YYYYMMDD, where the DD is the last day of the month MM. How do I
;; do this?
;;
;; The Date::Manip man page is over 2,600 lines long and grepping it
;; like a madman didn't help me, so I'm looking for a good spoon
;; feeding here. I promise to pay the USENET community back. Thank you.
Using Date::Manip would be overkill.
@last = (31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
$date =~ s/(\d\d\d\d)(\d\d)/"$1$2" . ($last[$2-1] ||
($1 % 4 ? 28 : $1 % 100 ? 29 : $1 % 400 ? 28 : 29))/e;
Abigail
--
$_ = "\x3C\x3C\x45\x4F\x54";
print if s/<<EOT/<<EOT/e;
Just another Perl Hacker
EOT
------------------------------
Date: 20 Dec 2000 17:32:37 -0700
From: tchrist@perl.com (Tom Christiansen)
Subject: Re: Directory Recursion Kwestion...
Message-Id: <3a414fa5@cs.colorado.edu>
In article <91raao$pkn$1@nnrp1.deja.com>,
Kai Jang <kai_jang@my-deja.com> wrote:
>Hi guys. I need a bit of help here. I have a sub routine that changes
>the name of all the directories under a specified directory into all
>lowercase. What I am trying to get it to do, is drill on down into the
>lower sub directories and change them too.
Use the Toolbox--the way God and Dennis intended.
% find topdir -type d -print | rename 'y/A-Z/a-z/'
--tom
#!/usr/bin/perl
# pathedit/rename/relink -- rename or relink files
# original rename and relink were by Larry Wall
# this version by Tom Christiansen
use strict;
use warnings;
our(
$errcnt, # how many didn't work
$verbose, # trace actions
$nonono, # but don't do them (implies verbose)
$careful, # ask if target *appears* to exist
$inspect, # ask about everything
$quiet, # don't carp if target skipped
$force, # overwrite existing target without prompting
$nullpaths, # stdin paths are null terminated, not \n
@flist, # list of magic filenames containing paths to edit
$renaming, # rename paths (disimplies reslinker)
$reslinking,# reslink paths (disimplies renamer)
);
$errcnt = 0;
opter();
compiler();
fixer();
exit($errcnt != 0);
sub usage {
warn "@_\n" if @_;
die <<EOF;
usage: $0 [-ifqI0vnml] [-F file] perlexpr [files]
-i ask about clobbering existent files
-f force clobbers without inquiring
-q quietly skip clobbers without inquiring
-I ask about all changes
-0 read null-terminate filenames
-v verbosely says what its doing
-n don't really do it
-m to always rename
-l to always symlink
-F path read filelist to change from magic path(s)
EOF
}
sub accesstty {
return 1 if defined fileno(TTYIN) &&
defined fileno(TTYOUT);
unless (open(TTYIN, "</dev/tty") && open(TTYOUT,">/dev/tty")) {
return 0;
}
select((select(TTYOUT),$|=1)[0]);
return 1;
}
sub compiler {
my $op = shift @ARGV || usage();
*pathedit = eval qq{
sub () {
use warnings qw/FATAL all/; # XXX: does not work
local \$SIG{__WARN__} = sub {
local \$_ = "\@_";
s/at \\(eval.*//;
die "FATAL WARNING: \$_";
};
$op;
}
} || do {
local $_ = $@;
s/at \(eval.*//s;
die "$0: can't compile perlexpr $op: $_\n";
}
}
sub get_targets {
if (@ARGV) {
usage "-L list exclusive of command line paths" if @flist;
return @ARGV;
}
@ARGV = @flist ? @flist : '-';
local $/ = "\0" if $nullpaths;
my @paths = <>;
chomp @paths;
return @paths;
}
sub fixer {
my $oldslink;
PATHNAME:
for my $oldname (get_targets()) {
if ($oldname =~ /\0/) {
warn "$0: null found in $oldname; did you forget -0?\n";
$errcnt++;
next PATHNAME;
}
if ($renaming && !-e $oldname) {
warn "$0: $oldname doesn't exist\n";
$errcnt++;
next PATHNAME;
}
if ($reslinking) {
unless (-l $oldname) {
warn "$0: $oldname ", (-e _)
? "not a symbolic link\n"
: "doesn't exist\n"
unless $quiet;
$errcnt++;
next PATHNAME;
}
$oldname = readlink($oldslink = $oldname);
}
my $newname = do {
local $_ = $oldname;
pathedit();
$_;
};
next if $newname eq $oldname;
local *confirm = sub () {
next PATHNAME unless accesstty();
print TTYOUT $renaming
? "rename $oldname to $newname? "
: "symlink $oldslink to point to $newname? ";
my $answer = <TTYIN>;
no warnings 'exiting';
last PATHNAME unless defined $answer; # exit?
chomp $answer;
last PATHNAME if "QUIT" =~ /^\Q$answer/i;
next PATHNAME unless "YES" =~ /^\Q$answer/i;
};
confirm() if $inspect;
# "I'd like to teach
# The world to race
# In perfect hackery!"
my $was_there = do {
no warnings 'newline';
-e $newname;
};
if ($renaming) {
if ($was_there && !$inspect && $careful) {
confirm() unless $force || $quiet;
next PATHNAME if $quiet;
}
unless (vrename($oldname, $newname)) {
warn "$0: can't rename $oldname to $newname: $!\n";
$errcnt++;
next PATHNAME;
}
}
elsif ($reslinking) {
unless ($was_there) {
warn "$0: symlinking $oldslink to nonexistent $newname\n"
unless $quiet;
}
unless (vunlink($oldslink)) {
warn "$0: can't unlink $oldslink: $!\n";
$errcnt++;
next PATHNAME;
}
if (!vsymlink($newname, $oldslink)) {
warn "$0: can't symlink $newname to $oldslink: $!\n";
$errcnt++;
next PATHNAME;
}
}
else {
die "Not reached";
}
}
}
sub vunlink {
my $goner = shift;
if ($verbose) {
print "unlink $goner\n";
return 1 if $nonono;
}
unlink $goner;
}
sub vrename {
my ($old,$new) = @_;
if ($verbose) {
print "rename $old $new\n";
return 1 if $nonono;
}
rename($old,$new);
}
sub vsymlink {
my ($new,$old) = @_;
if ($verbose) {
print "symlink $old -> $new\n";
return 1 if $nonono;
}
symlink($new,$old);
}
sub opter {
ARG: while (@ARGV && $ARGV[0] =~ s/^-(?=.)//) {
OPT: for (shift @ARGV) {
m/^$/ && do { next ARG; };
m/^-$/ && do { last ARG; };
s/^0// && do { $nullpaths++; redo OPT; };
s/^f// && do { $force++; redo OPT; };
s/^l// && do { $reslinking++; redo OPT; };
s/^I// && do { $inspect++; redo OPT; };
s/^i// && do { $careful++; redo OPT; };
s/^v// && do { $verbose++; redo OPT; };
s/^m// && do { $renaming++; redo OPT; };
s/^n// && do { $nonono++; redo OPT; };
s/^q// && do { $quiet++; redo OPT; };
s/^F(.*)//s && do { push @flist, $1 || shift @ARGV; redo OPT; };
usage("Unknown option: $_");
}
}
unless ($renaming || $reslinking) {
$renaming = $0 =~ /name/;
$reslinking = $0 =~ /link/;
}
if ($renaming && $reslinking) {
usage "Can't both rename (-r) and relink (-h)";
}
unless ($renaming || $reslinking) {
warn "$0: assuming renaming behavior requested\n";
$renaming++;
}
$verbose++ if $nonono;
if ($inspect) {
accesstty() || usage "can't inspect without /dev/tty: $!";
}
}
------------------------------
Date: Thu, 21 Dec 2000 00:37:05 GMT
From: Darren Dunham <ddunham@redwood.taos.com>
Subject: Re: Directory Recursion Kwestion...
Message-Id: <Rgc06.117$9u5.87828@news.pacbell.net>
Kai Jang <kai_jang@my-deja.com> wrote:
> Hi guys. I need a bit of help here. I have a sub routine that changes
> the name of all the directories under a specified directory into all
> lowercase. What I am trying to get it to do, is drill on down into the
> lower sub directories and change them too. I tried File::Find at
> first, but as has been documented, you can't change directory names
> using File::Find w/o it screwing up.
Huh? why not?
You should probably use finddepth instead of find. That will always
return a directory *after* it returns any children. Just make sure you
only change the final component at any time, and let earlier components
be changed by later calls.
--
Darren Dunham ddunham@taos.com
Unix System Administrator Taos - The SysAdmin Company
Got some Dr Pepper? San Francisco, CA bay area
< Please move on, ...nothing to see here, please disperse >
------------------------------
Date: Thu, 21 Dec 2000 01:54:20 +0100
From: Abe Timmerman <abe@ztreet.demon.nl>
Subject: Re: DSN/ODBC Client-Server Problem
Message-Id: <2nk24tgv56ums7ae6dk3lfebq3abnv6ic9@4ax.com>
On Wed, 20 Dec 2000 14:30:58 -0500, Stephan Gross <sg@loralskynet.com>
wrote:
...
> When I run the program while sitting at Server B, it works just fine.
> However, when I run the program across the network from a client PC,
> I get an ODBC message that it cannot connect to the database.
System DSN's are machine-bound, you probably want to look at the docs
for:
DBD::ODBC
section "Connect without DSN The ability to..."
--
Good luck,
Abe
perl -wle '$_=q@Just\@another\@Perl\@hacker@;print qq@\@{[split/\@/]}@'
------------------------------
Date: 21 Dec 2000 00:53:15 GMT
From: abigail@foad.org (Abigail)
Subject: Re: DSN/ODBC Client-Server Problem
Message-Id: <slrn942l3r.la8.abigail@tsathoggua.rlyeh.net>
Stephan Gross (sg@loralskynet.com) wrote on MMDCLXVIII September MCMXCIII
in <URL:news:1q124tkumh6hntbf33qgucmtiscbmtgq6h@4ax.com>:
,, I have a Microsoft Access database on Server A. I have a perl program
,, that connects to the database via ODBC on Server B. I have made the
,, database a System Data Source on Server B via the ODBC utility in the
,, Control Panel.
,,
,, When I run the program while sitting at Server B, it works just fine.
,, However, when I run the program across the network from a client PC,
,, I get an ODBC message that it cannot connect to the database.
I'd be highly surprised if all the information ODBC makes available to
you is that it cannot connect to the database. It's very likely it can
also tell you why.
Of course, this has nothing to do with Perl.
Abigail
--
BEGIN {$^H {q} = sub {$_ [1] =~ y/S-ZA-IK-O/q-tc-fe-m/d; $_ [1]}; $^H = 0x28100}
print "Just another PYTHON hacker\n";
------------------------------
Date: 20 Dec 2000 19:59:55 +0200
From: Juha Laiho <Juha.Laiho@iki.fi>
Subject: Re: Executing perl on linux
Message-Id: <91qs2r$ai7$1@ichaos.ichaos-int>
Jimmy Mc Namara <jmcnamara@iel.ie> said:
Trying to use the following because of varying perl interpreter paths:
>#!/bin/sh -- # -*- perl -*-
>eval 'exec perl -wS $0 ${1+"$@"}'
> if 0;
>
And getting the following error on a Linux box:
>sh: -- # -*- perl -*-: unrecognized option
>
[rest of error message snipped]
Most interesting. Manual pages for both bash and bash2 indicate that -- is
a valid flag, and is treated like - (that is, will terminate option
processing). Still, it appears not to be valid on the hashbang line; it
is valid when invoking bash interactively. I'd claim this is a bug in
GNU bash shell.
Apparently the "# -*- perl -*-" construct is there to force Emacs to
load the desired progamming mode (i.e. perl mode). At least on my machine
it appears that Emacs does not require that pattern to appear on the first
line; if I start the script with
#!/bin/sh
# -*- perl -*-
eval 'exec perl -wS $0 ${1+"$@"}'
if 0;
then the shell will not choke on the --, and Emacs will still go into perl
mode for editing the script, and the script does run under perl. So, I hope
this is an acceptable workaround.
--
Wolf a.k.a. Juha Laiho Espoo, Finland
(GC 3.0) GIT d- s+: a- C++ UH++++$ UL++++ P+@ L+++ E(-) W+$@ N++ !K w !O
!M V PS(+) PE Y+ PGP(+) t- 5? !X R tv--- b+ DI? D G e+ h--- r+++ y+
"...cancel my subscription to the resurrection!" (Jim Morrison)
------------------------------
Date: Thu, 21 Dec 2000 00:30:45 GMT
From: "Ed Grosvenor" <secursrver@hotmail.com>
Subject: Re: How do I use form email
Message-Id: <Vac06.1241$Sc1.42805@newsread2.prod.itd.earthlink.net>
OK, here's what you can do. Basically, you have two choices. One is to
grab a free account at hypermart www.hypermart.net . There you can install
Matt Wright's famous FormMail.cgi with the greatest of ease. You have to go
into the script itself and add your tripod server (name and IP address) to
the valid refferrers array. You can then call that script from your tripod
pages...
Like this: <form name="mailme"
action="http://serverX.hypermart.net/username/cgi-bin/FormMail.cgi"
method="post">
Or you can just use mailto as the action in your form like this:
<form name="mailme" action="mailto:address@domain.com">
Either one should do fine. Otherwise, you can look into what Tripod might
offer as an alternative. If they use qmail-inject (as many do), you can
just change the name of the mail program in your script. Most scripts have
something that looks like this:
$mail_prog = "/var/sendmail/bin/sendmail";
open (MAIL , "|$mail_prog);
print MAIL "To: $Recipient";
etc.etc.etc.
Just change the value of $mail_prog to whatever mail program your service
offers. Most of them are used in exactly the same manner. You just pipe
your data to them.
Good luck!
<nobull@mail.com> wrote in message news:u9ofy7ym2o.fsf@wcl-l.bham.ac.uk...
> anver@my-deja.com writes:
>
> > I'm new to Perl and CGI but I am rather familiar with HTML. I need
> > to collect information from a form and send the results to an email
> > address. All the free scripts available use a function called Sendmail
> > which is not supported by my host - www.tripod.com. It has its own
> > version called Tripodmail. If anyone has any information or advice
> > please reply.
>
> It is not at all clear what is your question is.
>
> Are you asking how to send mail from a Perl script? (See FAQ).
>
> Anyhow what is this "function called Sendmail" that you talk about?
> And in what way is it "not supported"?
>
> Are you asking for a tutorial on how to write CGI scripts in Perl?
> (See a tutorial on how to write CGI scripts in Perl)
>
> Are you asking about the API of a Tripod specific mechanism that you
> are required to use on Tripod? (See documentation on Tripodmail, I
> guess).
>
> --
> \\ ( )
> . _\\__[oo
> .__/ \\ /\@
> . l___\\
> # ll l\\
> ###LL LL\\
>
------------------------------
Date: Wed, 20 Dec 2000 22:55:35 GMT
From: nodo70@my-deja.com
Subject: HTML parse
Message-Id: <91rdd4$sbk$1@nnrp1.deja.com>
Can anyone point me to where I can get a resource of how to parse all
the links from HTML file? For example, I just want to get all the
links which is format under
<a href="htpp://wwww.name.com/test.html">Text</a>.
Your help is greatly appreciated.
Thanks,
noDo
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Wed, 20 Dec 2000 23:49:14 GMT
From: Adam Levenstein <cleon42@my-deja.com>
Subject: Re: HTML parse
Message-Id: <91rgho$uto$1@nnrp1.deja.com>
Depending on the file and style of coding, that can be incredibly
complicated. I'd suggest you look at matching using //, and tr//.
If it's *only* formatted as you have it, and each tag is on a newline,
you could do this:
open(file, 'file.html');
while (<file>) {
/<A HREF=/ && # do stuff here
}
What that will do is read in every line from file.html one at a time,
then "do stuff here" for any line that contains "<A HREF=".
Adam
In article <91rdd4$sbk$1@nnrp1.deja.com>,
nodo70@my-deja.com wrote:
> Can anyone point me to where I can get a resource of how to parse all
> the links from HTML file? For example, I just want to get all the
> links which is format under
> <a href="htpp://wwww.name.com/test.html">Text</a>.
>
> Your help is greatly appreciated.
>
> Thanks,
> noDo
>
> Sent via Deja.com
> http://www.deja.com/
>
--
-------------------------------------------------
Adam Levenstein
cleon42@my-deja.com
"Extraordinary claims require extraordinary evidence."
-- Carl Sagan
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Thu, 21 Dec 2000 00:09:25 GMT
From: jerome@activeindexing.com (Jerome O'Neil)
Subject: Re: HTML parse
Message-Id: <VSb06.1907$lz1.399447@news.uswest.net>
Adam Levenstein <cleon42@my-deja.com> elucidates:
>
>
> Depending on the file and style of coding, that can be incredibly
> complicated. I'd suggest you look at matching using //, and tr//.
[ Snip a realy bad idea guaranteed to fail except for the most
trivial cases.]
What he should realy do is visit his local CPAN repository, and gather
up the HTML::Parser modules, which makes this kind of thing trivial, for
even the most complex cases.
> then "do stuff here" for any line that contains "<A HREF=".
>> Can anyone point me to where I can get a resource of how to parse all
>> the links from HTML file? For example, I just want to get all the
>> links which is format under
OP: Generaly, HTML::Parser will be your friend for general HTML things.
For your specific case, (extracting links), use HTML::LinkExtor.
%perldoc HTML::LinkExtor
NAME
HTML::LinkExtor - Extract links from an HTML document
SYNOPSIS
require HTML::LinkExtor;
$p = HTML::LinkExtor->new(\&cb, "http://www.sn.no/");
sub cb {
my($tag, %links) = @_;
print "$tag @{[%links]}\n";
}
$p->parse_file("index.html");
Nifty!
HTH!
--
If men could learn from history, what lessons it might teach us! But
passion and party blind our eyes, and the light which experience gives
is a lantern on the stern, which shines only on the waves behind us.
--Samuel Taylor Coleridge, "Recollections"
------------------------------
Date: Wed, 20 Dec 2000 18:47:03 -0600
From: AP <alex@hoopsie2.com>
Subject: Re: No embeding please!
Message-Id: <3A415307.3EC4A6B3@hoopsie2.com>
> "Coding by hand" as opposed to "editing tools" give me the image of
> someone using his nails to cut out holes in a punchcard.
You mean you code this way too?
--
--------------------------------------------------
alex@hoopsie2.com | http://alex.hoopsie.com
--------- remove the "2" from e-mail -------------
------------------------------
Date: Wed, 20 Dec 2000 19:07:46 -0600
From: AP <alex@hoopsie2.com>
Subject: ok
Message-Id: <3A4157E2.6B67D49C@hoopsie2.com>
Ok, ok, I now know about the Benchmark module. Thanks for everyone's help.
Of course, after getting the suggestion from several of you, I found it in
the FAQ under "profiling". Don't worry, I won't post any "is x faster than
y" or "what's more efficient" questions. One request, though: if you're
rolling your eyes because I didn't try some document or resource when
attempting to solve a problem, just refer me to the document/resource
instead of going out and doing it for me, *then* telling me how dumb I am.
You can simply tell me how dumb I am and I'll go figure out what's needed so
you won't have to waste more of your time.
Again, my apologies...
Alex
--
--------------------------------------------------
alex@hoopsie2.com | http://alex.hoopsie.com
--------- remove the "2" from e-mail -------------
------------------------------
Date: Wed, 20 Dec 2000 15:44:37 -0800
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: perl DBI
Message-Id: <3A414465.9E918C54@vpservices.com>
[complimentary cc to Randal]
"Randal L. Schwartz" wrote:
>
> >>>>> "AvA" == AvA <a.v.a@home.nl> writes:
>
> AvA> i have a little database (12 rows) for testing (mysql) and i would like
> AvA> to show its data in 3 rows with each 4 querys in it.
>
>
> print table( map { Tr( map { td(escape_HTML($_)) } @$_ ) } @$two_d );
>
Minor quibble: it's escapeHTML, not escape_HTML.
ESP correction: As the OP clarified in a later posting, he/she wants
the output in 4 columns with each cell of the HTML table containg a row
from the database represented as a string. So here's a three level map
solution that will let one do that with any number of database columns
and any independently of that any number of HTML columns:
#!/usr/local/bin/perl -w
use strict;
use DBI;
use CGI qw(:all);
my $dbh = DBI->connect('dbi:RAM(RaiseError=>1):')
or die $DBI::errstr;
$dbh->func([<DATA>],'import');
my $table = $dbh->selectall_arrayref("SELECT * FROM table1");
$dbh->disconnect;
$table = put_into_columns($table,4);
print
header, start_html("My sample"), h1("My sample"),
table({-border=>1},
map { Tr(
map { td( join ' : ',
map{ escapeHTML($_) } @$_
) } @$_
) } @$table
),
end_html
;
sub put_into_columns {
my $table = shift;
my $num_columns = shift;
my $newrow;
my $newtable;
my $count=1;
for my $row(@$table) {
push @$newrow, $row;
if ($count % $num_columns == 0) {
push @$newtable, $newrow;
$newrow = [];
}
$count++;
}
push @$newtable, $newrow if scalar @$newrow;
return $newtable;
}
__END__
Joe,CT
Bev,OR
Floyd,TX
Mable,OK
Sue,WA
Bob,OR
Tom,ID
Ben,NY
Bubba,FL
Herb,FL
June,FL
Vera,MI
I'm sure the put_into_columns routine could be greatly improved upon but
my aim here was to use Randal's elegant map solution with slightly more
complexity to it to handle the OP's request.
--
Jeff
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 V9 Issue 5165
**************************************