[11129] in Perl-Users-Digest
Perl-Users Digest, Issue: 4729 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jan 23 03:06:51 1999
Date: Sat, 23 Jan 99 00:00:20 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sat, 23 Jan 1999 Volume: 8 Number: 4729
Today's topics:
Re: Am I wrong about Symbolic References? <burton@mcs.net>
Re: Am I wrong about Symbolic References? <burton@mcs.net>
Re: File Upload. <eugene@snailgem.org>
Re: First line skip when reading file <aqumsieh@matrox.com>
Re: How long would the Unixes last without Perl? <eugene@snailgem.org>
Re: LWP::Simple HELP!!! <eugene@snailgem.org>
Re: multi-dimensional arrays with hashes help please <aqumsieh@matrox.com>
Re: My in OOP <ebohlman@netcom.com>
Newbie question: writing file <chester@ma.ultranet.com>
Non character match? <kimn01@luey.redars.ca.boeing.com>
Re: Non character match? <ebohlman@netcom.com>
ODBC data access? (Henry Tu)
Re: Passing array references. <abey@hill.ucr.edu>
Re: pattern matching (details) <burton@mcs.net>
Re: Perl Criticism (David Formosa (aka ? the Platypus))
Re: Perl Criticism (David Formosa (aka ? the Platypus))
Re: Perl Criticism (David Formosa (aka ? the Platypus))
Re: PLease Help CGI configuration problem <eugene@snailgem.org>
Question concerning perl and NT <jewell@OnlineRAGE.com>
Regular Expression Help <igiffin@seattleopera.org>
Re: regular expression help <aqumsieh@matrox.com>
Re: Regular Expression Help <ebohlman@netcom.com>
Re: The Documeantion (was Re: Perl problem :(Offline mo <aqumsieh@matrox.com>
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 22 Jan 1999 23:13:32 -0600
From: Burton Kent <burton@mcs.net>
To: Sean McAfee <mcafee@waits.facilities.med.umich.edu>
Subject: Re: Am I wrong about Symbolic References?
Message-Id: <36A95A7C.F39D5835@mcs.net>
Thanks to Sean, Abraham and Ala for their help.
Appreciate it! This is one time where Perl
didn't "do what you expect."
Now I know what to expect.
Burton
Sean McAfee wrote:
>
> In article <36A750F0.34849453@mcs.net>, Burton Kent <burton@mcs.net> wrote:
> >I'm trying to use symbolic references to print a list of
> >variables. A vastly simplified listing follows.
>
> >My question is, how am I misunderstanding symbolic references?
>
> >--------------------------------------------------
> > my ($work_item_no, $request, $loc, $title, $impact,
> > $considerations, $timestamp, $validate, $approval,
> > $comment, $status)
> > = split ',' , "1,2,3,4,5,6,7,8,9,10,11";
> > for $field ( 'work_item_no', 'request', 'loc', 'title',
> > 'impact', 'considerations', 'timestamp', 'validate',
> > 'approval', 'comment', 'status') {
> > $symbolic = "${$field}";
> > print "$field: $symbolic\n";
> > }
>
> Symbolic references cannot be used to access lexical ("my") variables. Get
> rid of the "my", and it will work. In all likelihood, though, a much
> better solution is to use a hash:
>
> @fields = qw(work_item_no request loc title impact considerations
> timestamp validate approval comment status);
>
> @variable{@fields} = split ',', "1,2,3,4,5,6,7,8,9,10,11";
>
> for $field (@fields) {
> print "$field: $variable{$field}\n";
> }
>
> --
> Sean McAfee | GS d->-- s+++: a26 C++ US+++$ P+++ L++ E- W+ N++ |
> | K w--- O? M V-- PS+ PE Y+ PGP?>++ t+() 5++ X+ R+ | mcafee@
> | tv+ b++ DI++ D+ G e++>++++ h- r y+>++** | umich.edu
------------------------------
Date: Fri, 22 Jan 1999 23:14:00 -0600
From: Burton Kent <burton@mcs.net>
Subject: Re: Am I wrong about Symbolic References?
Message-Id: <36A95A98.245E3D8B@mcs.net>
Thanks Abraham. Especially for pointing it out
in the book.
Burton
Abraham Grief wrote:
>
> In the camel book, p. 255:
>
> Only package variables are visible to symbolic references. Lexical
> variables (declared with my) aren't in a package symbol table, and thus
> are invisible to this mechanism.
>
> On Thu, 21 Jan 1999, Burton Kent wrote:
>
> >
> > I'm trying to use symbolic references to print a list of
> > variables. A vastly simplified listing follows.
> >
> > My question is, how am I misunderstanding symbolic references?
> > According to my Camel book, this code should work!
> >
> > Thanks!
> >
> > Burton
> >
> > --------------------------------------------------
> > #!/opt/x11r6/bin/perl
> >
> > #This is perl, version 5.004_04 built for sun4-solaris (etc.)
> >
> > my ($work_item_no, $request, $loc, $title, $impact,
> > $considerations, $timestamp, $validate, $approval,
> > $comment, $status)
> > = split ',' , "1,2,3,4,5,6,7,8,9,10,11";
> >
> > for $field ( 'work_item_no', 'request', 'loc', 'title',
> > 'impact', 'considerations', 'timestamp', 'validate',
> > 'approval', 'comment', 'status') {
> > $symbolic = "${$field}";
> > print "$field: $symbolic\n";
> > }
> >
> >
------------------------------
Date: Sat, 23 Jan 1999 01:03:53 -0500
From: Eugene Sotirescu <eugene@snailgem.org>
Subject: Re: File Upload.
Message-Id: <36A96649.64D541A6@snailgem.org>
Robert Saunders wrote:
>
> Sam would you have a example of code you might use with the CGI.pm. I
> am interested in this topic. and would be interested in seeing some
> code to play with
>
Untested, just the idea:
use CGI;
use CGI::Carp 'fatalsToBrowser';
. . . . . . . . . .
#I assume you have something like this in your multipart form:
my $q->filefield(-name=>'file_2_upload');
my $file_2_upload = $q->param('file_2_upload');
. . . . . . . . . . .
my $file = "/usr/home/mydir/uploaded.gif";
binmode FH;
open (FH, ">$file") or die "Oy, can't open $file: $!";
while (my $bytesread=read($file_2_upload, my $buffer,1024)) {
print FH $buffer;
}
close FH or die "Can't close $file: $!";
Eugene
"I have an Apache Web Server that uses CGI forms written in COBOL."
Post in clpm
------------------------------
Date: Fri, 22 Jan 1999 18:41:46 -0500
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: First line skip when reading file
Message-Id: <x3y679yub7p.fsf@tigre.matrox.com>
"Gary C. New" <gnew@smip.com> writes:
>
> I've narrowed my problem down to this:
>
> When trying to use a simple while loop to read in multi. lines from a
> text file the first line of the file is always skipped.
I see ..
> # This opens the index.dat file for reading into @temp
> open(INDEX_DAT, "index.dat") || die "Can't open index.dat.\n";
Ok .. here you open your file for reading. You check for the return
value. Good.
> while (<INDEX_DAT>) {
This line actually reads the next line (which happens to be the first
one in the first iteration) and saves it into the default variable
$_. This is the source of your cofusion. You probably think of the
above line as "while there is something to read from the file" or
"while not eof" .. but in reality the diamond operator <FH> extracts
the next record from the filehandle FH, and returns it.
> @temp = <INDEX_DAT>;
This reads the rest of the file into the array @temp. Note that the
first line is in $_, not in @temp.
> }
> close(INDEX_DAT);
Check the result of your close() .. just like you do for the open().
Why do you need the while() statement? Just open() the file, read
everything into @temp, and close() it! No loops are needed. Please
also note that all of your lines contain a trailing \n character,
which you can chomp() off. But that's another issue.
>
> # This suggests that the first line del prob is prior to this code
> # open(INDEX_TMP, ">index.tmp") || die "Can't open index.tmp.\n";
> foreach $_ (sort @temp) {
> print "$_\n";
> }
> # close(INDEX_TMP);
> exit;
Why do you open INDEX_TMP here? I don't see you writing anything to
it!! Maybe you want to change your print statement above to:
print INDEX_TMP "$_\n";
> My text file (index.dat) looks simular to this:
> Bowden_Jeffrey_T # line 1
> Brimhall_Trent_S # line 2
>
> When I execute it at command line all I get is:
> >Brimhall_Trent_S
>
> Any clues as to why this is happening?
Hope this helps,
Ala
------------------------------
Date: Fri, 22 Jan 1999 23:54:52 -0500
From: Eugene Sotirescu <eugene@snailgem.org>
Subject: Re: How long would the Unixes last without Perl?
Message-Id: <36A9561C.290B9602@snailgem.org>
Kent Perrier wrote:
>
> "Phlip" <address@web.page> writes:
>
> > Newsgroupies
> >
> > Ever since Linux got me (not the other way around), I have observed
> > that
> > Perl is as close to an OS component as makes no difference.
> >
> > Is anyone out there running a Unix with no Perl installed?
>
> I don't think that there is a commercial UNIX on the market today that
> ships and installes perl by default.
>
> Kent
If by "commercial" you mean closed-source, you're probably right. But
both Caldera and RedHat sell their Linux distros with Perl as part of
the installation (Debian does too, but that might not be "commercial"
enough).
--
Eugene
"I have an Apache Web Server that uses CGI forms written in COBOL."
Post in clpm
------------------------------
Date: Sat, 23 Jan 1999 00:37:29 -0500
From: Eugene Sotirescu <eugene@snailgem.org>
To: Bob Freedman <bfreedman@esdim.noaa.gov>
Subject: Re: LWP::Simple HELP!!!
Message-Id: <36A96019.7567232B@snailgem.org>
Bob Freedman wrote:
>
> I am getting errors with code that I simply want to return me a web page
> a separated by lines. the code follows along with the command line and
> the error:
>
> CODE:
> #!/usr/local/bin/perl
>
> use LWP::Simple;
>
> $url = $ARGV[0];
> print $url,"\n";
> @document = split(/\n/,get($url));
> for $document (@document) {
> print $_,"\n";
> }
>
> COMMAND LINE:
> perl -w httptest.pl www.yahoo.com
>
> ERRORS:
> Use of uninitialized value at
> /usr/local/lib/perl5/site_perl/LWP/Protocol.pm line 107.
> Use of uninitialized value at
> /usr/local/lib/perl5/site_perl/LWP/Protocol.pm line 82.
> Use of uninitialized value at httptest.pl line 7.
#!/usr/local/bin/perl -w #don't forget your friend in need -w
use LWP::Simple;
$url = shift or die "Usage: $0 URL\n";
print $url,"\n";
$content = get($url);
@document = split(/\n/, $content);
for (@document) { #or foreach $line (@document) {
print $_,"\n"; #or print $line,"\n";
}
Though I don't understand why you want to do it this way: you first
split on newline, then you go and put the newline back!
$url = shift or die "Usage: $0 URL\n";
print $url,"\n";
getprint $url;
Would buy you the same thing, cheaper.
--
Eugene
"I have an Apache Web Server that uses CGI forms written in COBOL."
Post in clpm
------------------------------
Date: Fri, 22 Jan 1999 18:33:34 -0500
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: multi-dimensional arrays with hashes help please
Message-Id: <x3y90euuble.fsf@tigre.matrox.com>
Ramanujam Parthasarathi <partha@mihy.mot.com> writes:
>
> I would suggest an array of hash-references in your case. Consider the
> following code:
Isn't that what the original poster had?
>
> Chris Denman wrote:
>
> > Now, I know this code will not work:
> >
> > $founddata[0]{'name'}='Chris';
> > $founddata[0]{'age'}='27';
> > $founddata[1]{'name'}='Fred';
> > $founddata[1]{'age'}='Fred';
------------------------------
Date: Sat, 23 Jan 1999 06:22:46 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: My in OOP
Message-Id: <ebohlmanF601py.LHC@netcom.com>
Thomas Brian Holdren <irc_addict@hotmail.com> wrote:
: I am currently working on my first .pm that uses a variable that needs to be
: read by both the module and the calling script. Unfortunately, as a creature
: of habit, I like to use strict vars in all I do. Meaning a "my" declaration
: for $module::var. But, I cannot seem to get the value for $module::var from
: the calling script when I use "my" on it. I know that "my" doesn't store the
: variables it modifies in the package namespace (I think), and that that is why
: I can't get to it.
: My question is... is there anyway I can get at this "my" variable? (I don't
: think "local" is what I'm looking for). Should I just give up and throw away
: my precious strict vars?
No, you should make the variable a package global; take the 'my' off it
and declare it with 'use vars qw/var/;'. You'll also want to export it
or at least make it exportable; see perlmod or chapter 5 of the Camel.
------------------------------
Date: Sat, 23 Jan 1999 02:26:13 -0600
From: "Kevin D. Chester" <chester@ma.ultranet.com>
Subject: Newbie question: writing file
Message-Id: <36A987A3.E0A39ED5@ma.ultranet.com>
Hello Perl Group,
What am I doing wrong here?
#! /usr/local/bin/perl5.003
...
open(token_file, ">$token_file_name") || &err_trap("Cannot open
$token_file_name for writing\n");
print(token_file "$token\n");
close token_file;
...
All I get is "Cannot open tokens/262805729 for writing ".
Thanks for your help!
Kevin
------------------------------
Date: Sat, 23 Jan 1999 05:22:36 GMT
From: Namsuk Kim <kimn01@luey.redars.ca.boeing.com>
Subject: Non character match?
Message-Id: <36A95C9C.44FF@luey.redars.ca.boeing.com>
Hi folks,
Is there a simple way to express non-characters and number and few
special characters, * and - for matching?
In other words, !/[A-Za-z0-9*-]/.
I'd like to detect special charaters which are not allowed in our
databases' data.
Thanks,
Namsuk Kim
------------------------------
Date: Sat, 23 Jan 1999 06:59:52 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: Non character match?
Message-Id: <ebohlmanF603Fs.n2o@netcom.com>
Namsuk Kim <kimn01@luey.redars.ca.boeing.com> wrote:
: Is there a simple way to express non-characters and number and few
: special characters, * and - for matching?
: In other words, !/[A-Za-z0-9*-]/.
: I'd like to detect special charaters which are not allowed in our
: databases' data.
print "Illegal character: $1\n" if $field =~ /([^-*\w])/;
------------------------------
Date: Fri, 22 Jan 1999 22:13:43 -0800
From: henrytu@iname.com (Henry Tu)
Subject: ODBC data access?
Message-Id: <mPdq2.4911$IJ3.40267604@WReNphoon2>
Hi,
Can any one, please, show me or point me to where I
can get sample Perl code to generate a logon dialog
box for user to logon to MS SQL Server. I was able to
hard code userid and password and query data from
NSSQL server using win32::ODBC. I like to be able to
have user logon via a dialog box and act accordingly
based on the return code from SQL server. Thanks.
Henry
*** Posted from RemarQ - http://www.remarq.com - Discussions Start Here (tm) ***
------------------------------
Date: Fri, 22 Jan 1999 23:29:20 -0800
From: Abraham Grief <abey@hill.ucr.edu>
To: OM <om@republica.freeserve.co.uk>
Subject: Re: Passing array references.
Message-Id: <Pine.LNX.4.05.9901222324380.8962-100000@hill.ucr.edu>
Try using $$array[$numbers[0]] instead of $array[$numbers[0]]. I don't
know why you'd want to use a refernce instead of an of just passing an
array. Here's a little program that uses a function in the way you ask:
#!/usr/bin/perl
sub func
{
map {print "$$array[$_]\n"} @numbers;
}
$array = [10, 11, 12, 13];
@numbers = (1, 3);
&func($array, @numbers);
On Sat, 23 Jan 1999, OM wrote:
> How would I write a general function that takes two arguements, an array
> reference, say $array, and a list of numbers, say @numbers (should I be
> passing an array or a refernce here?).
> What I then want to do in the function is to only print elements of the
> array, as specified in the list of numbers.
>
> I've tried it a few times, but can't seem to get anywhere.
> It doesn't seem to like it when I try to give the subscript number directly,
> i.e print $array[$numbers[0]] etc. or some other variation.
>
>
> Thanks.
>
>
>
>
------------------------------
Date: Fri, 22 Jan 1999 23:23:07 -0600
From: Burton Kent <burton@mcs.net>
To: Xavier Cousin <cousin@ensam.inra.fr>
Subject: Re: pattern matching (details)
Message-Id: <36A95CBB.102287C3@mcs.net>
Xavier,
What's happening is that your code will pick up
"description" first. Then it compares description
against "other_description", which doesn't match.
So it appends "description" and "other_description"
When you compare descriptionoother_description to
the third line, of course it will not match.
Burton
bunfa-acche_M70Y+K285D description
bunfa-acche_M70Y+K285D other_description
> bunfa-acche_M70Y+K285D description
Xavier Cousin wrote:
>
> Hello i send earlier the following message but it appears some details
> are needed.
>
> *****************
> Message :
>
> Hello, i've got a pattern matching trouble in a perl script, here is an
> piece of the code dealing with the pattern matching :
>
> open (MUTSUB,tkkkout) or print "cant open tkkkout";
> while (<MUTSUB>){
> ($mutation,$reste) = split / /,$_,2;
> if ($kksub{$mutation} !~ /$reste/){
> $kksub{$mutation} .= $reste;
> }
> }
>
> here is an example of data found in 'tkkkout' file :
> bunfa-acche_M70Y+K285D
> <TR><TH><PRE>Acetylthiocholine</TH><TD><PRE>95.3 & 5.9 uM</TD><TD><PRE>-</TD><TD><PRE>
> T25C IS 50 mM phosphate</TD><TD><PRE><A
> href=/chol.cgi-bin/webace?db=achedb&class=Paper&object=
> Cousin_1996_J.Biol.Chem_271_15099>
> Cousin_1996_J.Biol.Chem_271_15099</A></TD></TR>
>
> *****************
> Details :
> In the input file 'tkkkout' i can have this kind of lines (simplified):
>
> bunfa-acche_M70Y+K285D description
> bunfa-acche_M70Y+K285D other_description
> bunfa-acche_M70Y+K285D description
>
> ...
>
> I want only one element of each kind :
> bunfa-acche_M70Y+K285D description
> bunfa-acche_M70Y+K285D other_description
>
> What i don't understand is that using the above scripts i i don't
> suppress doublets, i have :
>
> bunfa-acche_M70Y+K285D description
> bunfa-acche_M70Y+K285D other_description
> bunfa-acche_M70Y+K285D description
>
> description is a long line ending with a \n and $kksub{$mutation}
> contained several of these elements -> has several lines. May be is this
> the problem.
>
> Xavier
> --
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Xavier Cousin cousin@ensam.inra.fr
>
> INRA - DCC tel. (33) 04 99 61 28 14
> 2, place Pierre Viala fax (33) 04 67 54 56 94
> 34060 Montpellier Cedex 1
>
> ESTHER URL http://www.ensam.inra.fr/cholinesterase/
------------------------------
Date: 23 Jan 1999 06:57:53 GMT
From: dformosa@zeta.org.au (David Formosa (aka ? the Platypus))
Subject: Re: Perl Criticism
Message-Id: <slrn7aisnh.pa1.dformosa@godzilla.zeta.org.au>
In article <78b8n4$uo3$1@nnrp1.dejanews.com>, topmind@technologist.com wrote:
[...]
>I am only pointing out it's flaws as a general-purpose language.
>I would rather see a new language than a fixed Perl.
>
>BTW, why is it so important to have "more than one way"
>to write an IF statement? Variety || die?
Because we are not all the same people, because people like to express
things in diffrent ways. Because they wish to emphasise diffrent points.
--
Please excuse my spelling as I suffer from agraphia. See
http://www.zeta.org.au/~dformosa/Spelling.html to find out more.
How to win arguments on usenet http://www.zeta.org.au/~dformosa/usenet.html
------------------------------
Date: 23 Jan 1999 07:03:15 GMT
From: dformosa@zeta.org.au (David Formosa (aka ? the Platypus))
Subject: Re: Perl Criticism
Message-Id: <slrn7ait1j.pa1.dformosa@godzilla.zeta.org.au>
In article <78b9ed$v90$1@nnrp1.dejanews.com>, topmind@technologist.com wrote:
>In article <x7u2xmv444.fsf@home.sysarch.com>,
> Uri Guttman <uri@home.sysarch.com> wrote:
[...]
>> you have it backwards, dear bottommind as you are invading our turf so
>> it is up to you to provide code to back up your arguments.
>
>
>My claim is that most of the twistability in Perl can be eliminated
>without a great loss of productivity. If I provide an example,
>someone would eventually find a different way to do it and say
>"but you did not have to do it that way."
What is so wrong with this then? People are going to find fault in
your code. This is good because it will make you a better
programmer.
Perls power comes from its freedom to express things in multipal way,
if you can produce an equiverlent langage with the same expressive
power then I will be convined.
--
Please excuse my spelling as I suffer from agraphia. See
http://www.zeta.org.au/~dformosa/Spelling.html to find out more.
How to win arguments on usenet http://www.zeta.org.au/~dformosa/usenet.html
------------------------------
Date: 23 Jan 1999 07:07:17 GMT
From: dformosa@zeta.org.au (David Formosa (aka ? the Platypus))
Subject: Re: Perl Criticism
Message-Id: <slrn7ait95.pa1.dformosa@godzilla.zeta.org.au>
In article <78b9uc$vo5$1@nnrp1.dejanews.com>, topmind@technologist.com wrote:
[...]
>There were times when I put one equal sign instead of 2, and
>the compiler/interpreter saw it as a "leaky assignment"
>instead of a boolean. Still, compiler errors are annoying.
You know often perl will detect errors like that.
[dformosa@mcloon dformosa]$ perl -w
if ($a =2 ) {
print "Ouch!\n";
}
Found = in conditional, should be == at - line 1.
Ouch!
--
Please excuse my spelling as I suffer from agraphia. See
http://www.zeta.org.au/~dformosa/Spelling.html to find out more.
How to win arguments on usenet http://www.zeta.org.au/~dformosa/usenet.html
------------------------------
Date: Sat, 23 Jan 1999 00:12:56 -0500
From: Eugene Sotirescu <eugene@snailgem.org>
Subject: Re: PLease Help CGI configuration problem
Message-Id: <36A95A58.CA8082CC@snailgem.org>
bsh@mindspring.com@mindspring.com@mindspring.com wrote:
>
> Thanks for coming this far.
>
> I am a newbe when it comes to html, I installed perl5.004 on my spark 5 with
> the CGI modules. I am now getting a screen waiting with the message:
>
> (waitinig for HTTP query from standard output)
>
> any pointers as to what it is acutaly waiting for and/or how I can fix it.
It's waiting for you to read the documentation:
http://stein.cshl.org/WWW/software/CGI/cgi_docs.html
Look at the section that says:
"When you run a script from the command line, it says "offline mode:
enter name=value pairs on standard input". What do I do
now?"
--
Eugene
"I have an Apache Web Server that uses CGI forms written in COBOL."
Post in clpm
------------------------------
Date: Sat, 23 Jan 1999 00:23:25 -0500
From: "Ronnie D. Jewell" <jewell@OnlineRAGE.com>
Subject: Question concerning perl and NT
Message-Id: <36A95CCD.4908CF5D@OnlineRAGE.com>
Hi All,
I have a script that is supposed to read and append a file. I have
everything in the cgi-bin on a virtual host and when I run the script
from a browser it will read the file but will not allow me to write to
it.... I thought anything under the cgi-bin had full rights? Script
works corretly on unix machine.... I have even tried using the full path
to make sure it is correct.....
Any thoughts??
Thanks
--
RAGE Enterprises
Ronnie D. Jewell jewell@onlinerage.com
voice: 304-525-1898
http://www.onlinerage.com
------------------------------
Date: Fri, 22 Jan 1999 21:13:10 -0800
From: Ingrid Giffin <igiffin@seattleopera.org>
Subject: Regular Expression Help
Message-Id: <36A95A12.83DDED4D@seattleopera.org>
Hello,
Hoping someone can help with a Regular Expression.
I'm trying to search for an HTML string that does NOT contain a specific
other string.
Want to find all occurrences of
<IMG (......whatever.......)>
that do NOT contain the string "alt".
Haven't been able to find any information on excluding a whole string
within another string.
This expression is finding the larger string quite nicely:
<[^>]*img [^>]*>
(open the tag with "<", then have any sequence of characters except the
closing ">", followed by "img", then any sequence plus an ending ">".
So I need something like
<[^>]*img (mystery element goes here)>
But I can't seem to group the "alt" any way. Failures include:
[^alt] (merely excludes instances of a,
l, or t, as y'all know )
[^"alt"] (seems to mess up the whole
expression)
[^(alt)] ditto
plus have tried these in various combinations such as
[^"alt][^>]*
Any help is appreciated. Also, would greatly appreciate being cc'd with
any replies. Thank you!
------------------------------
Date: Fri, 22 Jan 1999 18:50:56 -0500
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: regular expression help
Message-Id: <x3y4spiuasf.fsf@tigre.matrox.com>
josh@sequoiasoft.com writes:
> I'm trying to chop the .jpg or .gif extensions off a filename, in Perl
> $afile = ($file =~ m:(.*)\\..*:);
> $file is the filename of the picture, eg. Pic1-2.jpg
> This returns an empty string. What am I doing wrong?
I can't figure out what your little regexp actually does!
It matches zero or more characters, followed by a literal "\" followed
by a character, then zero or more characters. No wonder it fails. Also
note that you are saving the result in a scalar context, which returns
either undef in case no matching occurs, or the number of matches.
Anyway .. read perlre ..
$file =~ s/\.(?:jpg|gif)//i;
this will modify $file itself.
($afile) = ($file =~ /^(.*)\.(?:gif|jpg)$/i);
This will keep $file intact, and will save the file name, without the
.gif or .jpg extension into $afile.
HTH,
Ala
------------------------------
Date: Sat, 23 Jan 1999 06:51:39 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: Regular Expression Help
Message-Id: <ebohlmanF60323.MoB@netcom.com>
Ingrid Giffin <igiffin@seattleopera.org> wrote:
: Hoping someone can help with a Regular Expression.
: I'm trying to search for an HTML string that does NOT contain a specific
: other string.
Regular expressions and HTML mix like oil and water.
: Want to find all occurrences of
: <IMG (......whatever.......)>
: that do NOT contain the string "alt".
You don't want to find a string that doesn't contain another string; you
want to find an HTML element that doesn't contain a specific attribute.
You do that by using HTML::Parser, something like this (UNTESTED!):
package AltCheck;
use base qw/HTML::Parser/;
sub start {
my ($self,$tag,$attr,$attrseq,$orig)=@_;
if ($tag eq 'img' and not (exists $attr->{alt}) {
print "No ALT attribute for ",$attr->{src},"\n";
}
}
package main;
my $p=new AltCheck;
$p->parse_file("myfile.html");
If your goal is to actually perform substitutions on the HTML, check out
HTML::Filter (which will require learning HTML::Parser).
------------------------------
Date: Fri, 22 Jan 1999 19:03:27 -0500
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: The Documeantion (was Re: Perl problem :(Offline mode...)
Message-Id: <x3y3e52ua7n.fsf@tigre.matrox.com>
don_hosek@my-dejanews.com writes:
> The FAQ for Perl at www.perl.com is devoid of basic usability features (e.g.,
> links to questions and answers from the TOC). I've been rapidly coming up to
> speed with Perl 5 the past couple of weeks and I couldn't find answers to
> some of the basic questions like how to make two-dimensional arrays & the
did you read perldsc by any chance?
> like in the FAQ. Trying to figure out which of the big perldoc pages to find
> some information in is not intuitive to the newcomer. The CPAN web interface
Just doing a little search in perltoc (usually) points me to the
proper direction in less than 5 seconds.
> is also a bit perplexing to the newcomer. A better interface could do a lot
> to eliminate many questions which are answered with "the XXX module does
> exactly what you need."
It is very hard to satisfy everyone all the time. The people that
maintain CPAN have so much to do, you can't really blame them.
> In an ideal world, before posting a query to a newsgroup, one should try to
> find the information in printed and on-line manuals, including a search for
> previous inquiries on dejanews. In practice this doesn't happen.
why? I think that most people are just too lazy. Some people even have the
attitude that :
"I am so important, I can't waste my time on this. You
have to solve it for me, for free. You can spare a few minutes to
solve my problem. I can't."
Those kind of people won't even bother checking out manuals even if
you tell them exactly what to do.
> Personally, I don't think that it takes that much more effort to give an
> answer along the lines of:
>
> You can get that sort of functionality using XXX. Try perldoc -f XXX for full
> details.
Most of the times this is what happens, sometimes even a short snippet from
the actual FAQ is supplied. I see plenty of those every day.
> than to be snippy and post something like
>
> rtfm, you stupid twit.
I don't agree with the behaviour you outline above, but when someone
asks a silly qustion like "what is a line in Perl?" or "How do I use
(any function)?" most people get upset. If someone wants to write a
little program using a specific language, then s/he should at least read
on the basics of that language. A lot of the people who post here
don't even bother. This behaviour triggers the above responses.
> If you're not willing to be helpful, why bother posting a reply?
It's more psychological than anything else .. really :-)
> -dh (who knows more than some, less than many, but is at least willing to help
> as best as he is able).
We need more of that :-)
------------------------------
Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>
Administrivia:
Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing.
]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body. Majordomo will then send you instructions on how to confirm your
]subscription. This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.
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.misc (and this Digest), send your
article to perl-users@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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 4729
**************************************