[16089] in Perl-Users-Digest
Perl-Users Digest, Issue: 3501 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jun 28 14:05:37 2000
Date: Wed, 28 Jun 2000 11:05:16 -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: <962215515-v9-i3501@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 28 Jun 2000 Volume: 9 Number: 3501
Today's topics:
Re: # of occurrances in a list (Randal L. Schwartz)
$_ <rbank@csf.edu>
Re: $_ <pap@NOTHEREsotonians.org.uk>
Re: $_ (jason)
Re: (Resolution) Is SymLink broken? It won't take scala design@raincloud-studios.com
Re: - Learn how to SPEED UP your INTERNET connection b <bg@skypoint.com>
Re: \ and single quote <franl-removethis@world.omitthis.std.com>
Re: Calling object functions <stephen.kloder@gtri.gatech.edu>
Re: Calling object functions (Marty Pauley)
cgi question <rbank@csf.edu>
Re: cgi question <foo@bar.va>
Re: cgi question <news@webneeds.com>
Re: dereferencing question <billy@arnis-bsl.com>
Re: Finding the directory of the current script <juex@deja.com>
Re: Finding the directory of the current script <juex@deja.com>
Re: Golf problem (Gwyn Judd)
Re: Golf problem (Martin Pauley)
Re: Golf problem (Leo Schalkwyk)
Re: Golf problem (Abigail)
Re: Golf problem (Marty Pauley)
Re: HELP ME PLEASE !!!! <dmeyers@panix.com>
Re: Help with 'If' condition - newbie <abe@ztreet.demon.nl>
Help: regex for changing NON-absolute urls in a html fi <jbessels@planet.nl>
Re: Help: regex for changing NON-absolute urls in a htm <arnet@hpcvplnx.cv.hp.com>
Re: Help: regex for changing NON-absolute urls in a htm <bwalton@rochester.rr.com>
Re: Help: regex for changing NON-absolute urls in a htm preetham@my-deja.com
Re: How to access all the files in a dir including its (Randal L. Schwartz)
Re: how to count number of line in a file ? <franl-removethis@world.omitthis.std.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 28 Jun 2000 08:53:30 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: # of occurrances in a list
Message-Id: <m1n1k5vm2t.fsf@halfdome.holdit.com>
>>>>> "Colby" == Colby Hansen <cghansen@micron.com> writes:
Colby> I'm using the following to find the number of unique items in a list:
Colby> my %unique = ();
Colby> @unique{@list} = (undef) x scalar @list;
Colby> my $uniquecount = scalar keys %unique;
Colby> This works great! Now I'm looking for a slick way to determine how many
Colby> occurrances of one particular item there are. Thanks!
The "scalar" there is redundant. As is the entire right side of the
assignment. So you can simplify your stuff to this:
my $count = do { my %unique; @unique{@list} = (); keys %unique };
However, to do both your first question and your second question, I'd
do this:
my %counts; $counts{$_}++ for @list;
for (keys %counts) { print "$_ was seen $counts{$_} times\n" }
print "there are ".(keys %counts)." unique items\n";
print "Just another Perl hacker,"
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Wed, 28 Jun 2000 09:29:24 -0600
From: "Robin Bank" <rbank@csf.edu>
Subject: $_
Message-Id: <8jd7el$1c5a$1@reader.nmix.net>
What exactly does $_ signify? What's the variable name? Just out of
curiousity.
Thanks,
--
Robin Bank
rbank@csf.edu
------------------------------
Date: Wed, 28 Jun 2000 17:07:06 +0100
From: Paul Taylor <pap@NOTHEREsotonians.org.uk>
Subject: Re: $_
Message-Id: <395A22AA.AA79C17A@NOTHEREsotonians.org.uk>
Robin Bank wrote:
>
> What exactly does $_ signify? What's the variable name? Just out of
> curiousity.
>
It's the default variable. Its value depends on the context in which it
is used.
e.g.
foreach (@thing) {
print "$_\n" ;
}
The default variable in that context is each value of the list. I'd
really recommend
reading some of the fine Perl books out there to find out what it
becomes in
which context.
Pap.
------------------------------
Date: Wed, 28 Jun 2000 16:27:13 GMT
From: elephant@squirrelgroup.com (jason)
Subject: Re: $_
Message-Id: <MPG.13c4c4a2ce97032798975b@news>
Robin Bank writes ..
>What exactly does $_ signify? What's the variable name? Just out of
>curiousity.
check out the perlvar documentation by typing the following at a command
prompt on a machine with Perl installed
perldoc perlvar
--
jason - elephant@squirrelgroup.com -
------------------------------
Date: Wed, 28 Jun 2000 17:49:13 GMT
From: design@raincloud-studios.com
Subject: Re: (Resolution) Is SymLink broken? It won't take scalars
Message-Id: <8jddqg$krc$1@nnrp1.deja.com>
> symlink takes two scalar values. Whether they're literal strings,
> or scalar variables it doesn't matter. Clearly Something Else is
> wrong. You're not putting the right values into the variables,
> you're mixing them up...something.
I discovered the problem... it's pretty strange, a nice investigation
if someone is interested. I was not implementing symlink correctly but
it allowed me to do some things that didn't seem consistent. I was
intending to set up a link to a directory from which the file could be
downloaded so mysite.com/hidden/special would be linked from
mysite.com/1234-12345678 and the setup.exe in the previous path could
be downloaded from the secondary numerical directory.
The problem was that in my original code I was including the exe as
well. So symlink was correctly catching that 1234-12345678 did not
exist, hence the directory does not exist error. Here's where it gets
inconsitent though:
1) If you use NO scalars and pass the full paths including the
setup.exe file directly to symlink it *creates* the 1234xxx directory
and a setup.exe symbolic link within that directory with no 'directory
not found message'. It returns a 1 for success but $! contains
Directory not found.
2) If you DO use scalars to represent your paths then symlink catches
the missing directory and bombs. I could not find anything in my
searches to reveal why this is happening. This time it returns a 0 and
Directory not found.
This seems slightly erroneous to a new symlink user such as myself.
CT
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 28 Jun 2000 12:31:56 -0500
From: "Barry Grupe" <bg@skypoint.com>
Subject: Re: - Learn how to SPEED UP your INTERNET connection by 70-100% for FREE!
Message-Id: <8jdd14$2tv4$1@shadow.skypoint.net>
Just curious, does anybody track the headers for junk like this and contact
the offender's provider?
<uyurpz@speedyinternet.com> wrote in message
news:iIT55.93842$m5.59849@typhoon.kc.rr.com...
> Hey,
> Sign up at Netsetter (for free!), and it will install some free software
that will speed up you Internet connection by 100%! It helped me a lot with
my connection! I now download a lot faster than before, and get lower pings
in games, which eliminates lag!
> Read more about it on their site if you doubt it!
> Get it here:
> http://speedyinternet.cjb.net
>
------------------------------
Date: Wed, 28 Jun 2000 16:55:07 GMT
From: Francis Litterio <franl-removethis@world.omitthis.std.com>
Subject: Re: \ and single quote
Message-Id: <m37lb9iw44.fsf@franl.andover.net>
"Dan Manion" <news@webneeds.com> writes:
> I'm afraid you've not left much for us to discuss. Maybe post the actual
> line that you saw this so we can get a sense for what context this statement
> was used in and why.
It looks to me like he posted a syntactically correct one-line Perl
program whose execution has no side effects:
'three \\\'s: "\\\\\"';
Then he asked about the way Perl parses the string constant. I don't
think any additional context is needed.
> "-newbie" <-newbie_member@newsguy.com> wrote in message
> news:8jb3io$e1d@drn.newsguy.com...
> > Sorry if this upsets you, but it was the first message ever I sent to this
> > group. Did anyone discussed this before?
> >
> > TIA
> >
> > -gl
> >
> > In article <3958FAA0.A6EC0B3F@attglobal.net>, Drew says...
> > >
> > >-newbie wrote:
> > >>
> > >> Hi gurus:
> > >>
> > >> I have trouble to understand this one:
> > >>
> > >> 'three \\\'s: "\\\\\"';
> > >>
> > >> I understood the first part: the first \ escapes the second \; the
> third \
> > >>escapes the single ' right before the letter "s"; but I am trying to
> confirm the
> > >>second part: the first \ right after " escapes the second \; the third \
> escapes
> > >>the forth \ and last \ right before " stay it is because of the single
> quote; am
> > >> I right?
> > >
> > >It is good manners not to start a new thread to discuss the same matter
> > >that you were previously discussing in a prior thread.
> > >
> > >Please keep that in mind.
------------------------------
Date: Wed, 28 Jun 2000 12:47:12 -0400
From: Stephen Kloder <stephen.kloder@gtri.gatech.edu>
Subject: Re: Calling object functions
Message-Id: <395A2C10.43C49AAB@gtri.gatech.edu>
"Thomas J. Boberek" wrote:
>
> $thisDevice = new deviceObject;
> $section = 'lccc';
> $test = $thisDevice->$section;
>
> What this is supposed to do is return the value of the $lccc variable in
> the deviceObject. This is the function:
>
> sub lccc {
> return $lccc;
> }
Why not use $section = \&lccc; instead?
------------------------------
Date: Wed, 28 Jun 2000 17:18:36 GMT
From: marty@kasei.com (Marty Pauley)
Subject: Re: Calling object functions
Message-Id: <slrn8lkcmj.6ln.marty@deimos.kasei.com>
Thomas J. Boberek wrote:
>$thisDevice = new deviceObject;
>$section = 'lccc';
>$test = $thisDevice->$section;
>I have a number of functions like this, and wish to cycle through them,
>which is why I use a variable to hold the function name that I wish to
>execute. I get a syntax error everytime I run this, right at the
>$section. So, I was wondering if there was any way to do this, or is it
>just impossible?
Do:
$test = $thisDevice->$section();
instead. The parens are enough of a clue to let perl know what you mean.
--
Marty
------------------------------
Date: Wed, 28 Jun 2000 09:37:14 -0600
From: "Robin Bank" <rbank@csf.edu>
Subject: cgi question
Message-Id: <8jd7el$1c5a$2@reader.nmix.net>
Can someone give me an idea of how to do a user database with usename,
password, and login information? I have to create a PERL CGI message forum
where a user signs in and then is able to post messages, and accounts have
to be created dynamically from a sign up form. The one problem I have is the
fact that I don't have any sort of database access on my server. All I need
are suggestions are to what the best options would be for this kind of
system, the general implementation. I can do the programming, if I know what
I'm writing.
Thanks in advance,
--
Robin Bank
rbank@csf.edu
------------------------------
Date: Wed, 28 Jun 2000 18:05:49 +0200
From: Marco Natoni <foo@bar.va>
Subject: Re: cgi question
Message-Id: <395A225D.1B483F9B@bar.va>
Robin,
Robin Bank wrote:
> Can someone give me an idea of how to do a user database with
> usename, password, and login information? I have to create a PERL
> CGI message forum where a user signs in and then is able to
> post messages, and accounts have to be created dynamically from a
> sign up form. The one problem I have is the fact that I don't have
> any sort of database access on my server.
Use the simplest existing database: A text file! :)
At least one DBD driver for text-file-based DB exists on the CPAN and
with the front-end DBI module you can use it like any other database.
OR
Study what the tie function does and use the Berkley DB file
framework.
Best regards,
Marco
------------------------------
Date: Wed, 28 Jun 2000 11:25:01 -0600
From: "Dan Manion" <news@webneeds.com>
Subject: Re: cgi question
Message-Id: <qms65.133$%O.185471@news.uswest.net>
Try looking at DB_File. You can grab a copy off CPAN.
"Robin Bank" <rbank@csf.edu> wrote in message
news:8jd7el$1c5a$2@reader.nmix.net...
> Can someone give me an idea of how to do a user database with usename,
> password, and login information? I have to create a PERL CGI message forum
> where a user signs in and then is able to post messages, and accounts have
> to be created dynamically from a sign up form. The one problem I have is
the
> fact that I don't have any sort of database access on my server. All I
need
> are suggestions are to what the best options would be for this kind of
> system, the general implementation. I can do the programming, if I know
what
> I'm writing.
>
> Thanks in advance,
> --
> Robin Bank
> rbank@csf.edu
>
>
>
------------------------------
Date: Wed, 28 Jun 2000 15:06:57 GMT
From: Ilja Tabachnik <billy@arnis-bsl.com>
Subject: Re: dereferencing question
Message-Id: <8jd4a0$cp4$1@nnrp1.deja.com>
In article <395A06BD.1654ECAF@americasm01.nt.com>,
naidenm@nortelnetworks.com wrote:
> I have the following data structure
>
> $entry <--- hashref
>
> $entry ={
>
> key1 => [
>
> [
> val1,
> val2
> ],
> [
> val3,
> val4
> ],
> [
> val5,
> val6
> ]
>
> key2 => [
> [
> val7,
>
> etc...
>
> In short I can access the elements in $entry's anonymous arrays like
> this
> $entry->{'key1'}[0][1] and this will give me val2.
>
> My question is how can I get the size of the outermost anon array
[eg..
> in the example the size of the outermost is 3 and the inermost is 2]
> I tried a couple of variations using # but non of them worked for me.
>
As usually, just evaluate an array in scalar context:
my $outer_size = @{$entry->{key1}};
my $inner_size = @{$entry->{key1}[1]};
Hope this helps.
Ilja.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 28 Jun 2000 10:16:39 -0700
From: "Jürgen Exner" <juex@deja.com>
Subject: Re: Finding the directory of the current script
Message-Id: <395a32f3$1@news.microsoft.com>
<conic@bigpond.com> wrote in message news:8jbi4t$94r$1@nnrp1.deja.com...
> Is there a way for a script to realise what directory it is in? I want
> to examine files that are in the same directory as the script, but also
> to be able to move the script to any directory without changing it.
That is impossible because that directory might not even exist at that time
any more (starting the script, then renaming or deleting the dir, then the
script tries to determine the dir).
BTW: Even considering that for most OSs hardlinks for directories are not
supported there is still the question which of two dozen different softlinks
you would like.
jue
------------------------------
Date: Wed, 28 Jun 2000 10:18:55 -0700
From: "Jürgen Exner" <juex@deja.com>
Subject: Re: Finding the directory of the current script
Message-Id: <395a337c$1@news.microsoft.com>
"Sami Maki" <sami.maki@nokia.com> wrote in message
news:tog65.4226$AM5.52548@news1.nokia.com...
[de-jeopardized quotations]
> conic@bigpond.com wrote in message <8jbi4t$94r$1@nnrp1.deja.com>...
> >Is there a way for a script to realise what directory it is in? I want
> >to examine files that are in the same directory as the script, but also
> >to be able to move the script to any directory without changing it.
> To get path of current working directory..
>
> use Cwd;
> print cwd();
But the CWD is a property of the shell and has nothing to do with the
location of the script in the file tree.
jue
------------------------------
Date: Wed, 28 Jun 2000 15:15:58 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Golf problem
Message-Id: <slrn8lk5la.pg5.tjla@thislove.dyndns.org>
I was shocked! How could Peter Marksteiner <hump@katz.cc.univie.ac.at>
say such a terrible thing:
>Suppose you want to find words with exactly ten non-repeating letters such
>as "binoculars", "fishmonger", or "paintbrush", suitable for games or simple
>encryption of numbers where every decimal digit is represented by a letter.
>
>I've tried to write the shortest possible Perl program to extract
>such words from a wordlist and have found the following two solutions:
>
>perl -pe '%c=();length==11&!grep{$c{$_}++}split""or$_=""' /usr/dict/words
>perl -pe '$_=""if(keys%{{map{$_,1}split""}})*length!=121' /usr/dict/words
>
>Is there anybody who can do it with fewer keystrokes?
perl -pe 'my%c;length==11&!grep{$c{$_}++}split""or$_=""' /usr/dict/words
saves one character but it is kind of cheap. I wanted to find something
better that didn't steal from yours (much). I went through all these:
perl -F// -pae 'my%c;length==11&!grep{$c{$_}++}@F or$_=""' /usr/dict/words
perl -F// -pae '$_=""if(keys%{{map{$_,1}@F}})*length!=121' /usr/dict/words
perl -F// -pae '%_=map{$_,1}@F;$_=""if(keys%_)*length!=121' /usr/dict/words
before I came up with:
perl -F// -pae '%_=map{$_,1}@F;$_=""if(keys%_)*@F!=121' /usr/dict/words
which is better and then:
perl -F// -pae '$_=""if(keys%{{map{$_,1}@F}})*@F!=121' /usr/dict/words
which is better again saving three strokes over yours :) Quite a difficult
challenge that. Bit of a learning experience.
--
Gwyn Judd (tjla@guvfybir.qlaqaf.bet)
My return address is rot13'ed
If you don't have time to do it right, where are you going to find the time
to do it over?
------------------------------
Date: Wed, 28 Jun 2000 15:19:32 GMT
From: marty@deimos.kasei.com (Martin Pauley)
Subject: Re: Golf problem
Message-Id: <slrn8lk5p8.14r.marty@deimos.kasei.com>
In article <slrn8ljm2r.ka1.abigail@alexandra.delanet.com>, Abigail wrote:
>Peter Marksteiner (hump@katz.cc.univie.ac.at) wrote on MMCDXCIII
>September MCMXCIII in <URL:news:8jcgqm$29vm$1@www.univie.ac.at>:
>][ perl -pe '$_=""if(keys%{{map{$_,1}split""}})*length!=121' /usr/dict/words
>][
>][ Is there anybody who can do it with fewer keystrokes?
>
>Saving one stroke:
>
> perl -pe '%c=();/^.{10}$/&!grep{$c{$_}++}split""or$_=""' /usr/dict/words
Saving another 2 strokes (but retaining the 'Stravinsky' problem):
perl -F'""' -ane 'my%c;@c{@F}=1;@F*keys%c==121&&print' /usr/dict/words
--
Marty
------------------------------
Date: 28 Jun 2000 17:02:45 GMT
From: schalkwy@minnie.molgen.mpg.de (Leo Schalkwyk)
Subject: Re: Golf problem
Message-Id: <8jdb3k$bme5$1@fu-berlin.de>
Gwyn Judd (tjla@guvfybir.qlaqaf.bet) wrote:
: I was shocked! How could Peter Marksteiner <hump@katz.cc.univie.ac.at>
: >Suppose you want to find words with exactly ten non-repeating letters such
summary of the score so far:
perl -pe'%c=();length==11&!grep{$c{$_}++}split""or$_=""' Peter
perl -pe'$_=""if(keys%{{map{$_,1}split""}})*length!=121' Peter
perl -pe'%c=();/^.{10}$/&!grep{$c{+lc}++}split""or$_=""' Abigail ('lc' spec)
perl -F'""' -ane 'my%c;@c{@F}=1;@F*keys%c==121&&print' Marty
perl -F// -pae'$_=""if(keys%{{map{$_,1}@F}})*@F!=121' Gwynn
perl -pe'%c=();$_=""if!/^.{10}$/|grep{$c{+lc}++}/./g' Andrew
my 2 strokes' worth
perl -ne'@x{%x=@x=/./g}=1;@y=%x;@y*@x==200&&print' Leo
perl -ne'@x{%x=@x=lc=~/./g}=1;@y=%x;@y*@x==200&&print' Leo ('lc' spec)
of course I stole /./g from Andrew ....
Leo
--
------------------------------------------------------------
schalkwy@molgen.mpg.de
------------------------------
Date: 28 Jun 2000 13:35:39 EDT
From: abigail@delanet.com (Abigail)
Subject: Re: Golf problem
Message-Id: <slrn8lket6.ka1.abigail@alexandra.delanet.com>
Gwyn Judd (tjla@guvfybir.qlaqaf.bet) wrote on MMCDXCIII September
MCMXCIII in <URL:news:slrn8lk5la.pg5.tjla@thislove.dyndns.org>:
||
|| perl -F// -pae '$_=""if(keys%{{map{$_,1}@F}})*@F!=121' /usr/dict/words
And saving one more stroke:
perl -F// -pae 'my%F;@F{@F}=();$_=""if@F*keys%F!=121' /usr/dict/words
But that's still one more that from the other subthread:
perl -pe 'my%c;$_=""if!/^.{10}$/|grep{$c{$_}++}/./g' /usr/dict/words
Howeverm we can do better, by twisting the problem statement. It
didn't say we have to find all words from /usr/dict/words matching the
criteria. If we settle for a subset of words, we can do:
perl -F// -pae 'my%F;@F{@F}=();$_=""if@F*%F!=121' /usr/dict/words
Abigail
--
echo "==== ======= ==== ======"|perl -pes/=/J/|perl -pes/==/us/|perl -pes/=/t/\
|perl -pes/=/A/|perl -pes/=/n/|perl -pes/=/o/|perl -pes/==/th/|perl -pes/=/e/\
|perl -pes/=/r/|perl -pes/=/P/|perl -pes/=/e/|perl -pes/==/rl/|perl -pes/=/H/\
|perl -pes/=/a/|perl -pes/=/c/|perl -pes/=/k/|perl -pes/==/er/|perl -pes/=/./;
------------------------------
Date: Wed, 28 Jun 2000 17:52:13 GMT
From: marty@kasei.com (Marty Pauley)
Subject: Re: Golf problem
Message-Id: <slrn8lkel8.6ln.marty@deimos.kasei.com>
In article <8jdb3k$bme5$1@fu-berlin.de>, Leo Schalkwyk wrote:
>summary of the score so far:
>perl -pe'%c=();length==11&!grep{$c{$_}++}split""or$_=""' Peter
>perl -pe'$_=""if(keys%{{map{$_,1}split""}})*length!=121' Peter
>perl -pe'%c=();/^.{10}$/&!grep{$c{+lc}++}split""or$_=""' Abigail ('lc' spec)
>perl -F'""' -ane 'my%c;@c{@F}=1;@F*keys%c==121&&print' Marty
D'OH!
I could have saved another 3 with:
perl -F// -ane'my%c;@c{@F}=1;@F*keys%c==121&&print'
But it still wouldn't be as good as Leo.
Must do better...
--
Marty
------------------------------
Date: 28 Jun 2000 13:31:06 -0400
From: David Meyers <dmeyers@panix.com>
Subject: Re: HELP ME PLEASE !!!!
Message-Id: <yobk8f9pvad.fsf@panix2.panix.com>
Jakob Schmidt <sumus@aut.dk> writes:
> "Lee Millard" <lee.millard@ntlworld.com> writes:
>
> > How do I get my script to display a list of directories that are in the same
> > directory as the script ???
>
> opendir DIR, '.';
Note, of course, that the script doesn't necessarily (or even likely)
live in '.'. That's the working directory and not only has it no
relation to where the script lives, it can even change in the course
of the script running. Nevertheless, while it's not what the OP
asked for, it's probably what he meant. In case he actually did
mean the directory wherein the script itself resides, look up "FindBin".
> while ( $_ = readdir DIR ) { -d $_ and print $_, "\n" }
Nicely done.
Add error checking to the opendir and, if the dir opened is,
indeed, not ., prepend the directory in question to $_ for the -d.
> This works if '.' gives you the directory of the script. I'm not sure if it
> does that in all CGI environments - if that's where you need it - but it does
> in mine.
cgi has nothing to do with it...
--d
------------------------------
Date: Wed, 28 Jun 2000 17:22:40 +0200
From: Abe Timmerman <abe@ztreet.demon.nl>
Subject: Re: Help with 'If' condition - newbie
Message-Id: <ff5klsg42hvfltnk2d7pu44aujnjcv6iqe@4ax.com>
On 27 Jun 2000 23:24:00 GMT, mtshupp@aol.com (Mtshupp) wrote:
> Hello,
>
> Perl newbie here -- I'm attempting to modify a script; I'm trying to describe
> a condition such that if a subtotal is less than 6.00, a shipping fee is 2.00;
> 6.00 - 9.99, shipping fee is 3.00; ...and so forth. The amounts are
> arbitrarily set.
>
> So far, I have:
...
> I'd be very grateful for any help pointing me in the right direction. The
> amounts I'm trying to use are:
...
#!/usr/bin/perl -w
use strict;
my @ship_fee = (
[0 => 2],
[6 => 3],
[10 => 3.5],
[15 => 4],
[20 => 5],
);
my $order = 19.95;
my $ship;
for (reverse @ship_fee) {
$order >= $_->[0] and $ship = $_->[1] and last;
}
printf "%.2f -> %.2f\n", $order, $ship;
__END__
--
Good luck,
Abe
------------------------------
Date: Wed, 28 Jun 2000 17:26:40 +0200
From: Jan Bessels <jbessels@planet.nl>
Subject: Help: regex for changing NON-absolute urls in a html file.
Message-Id: <395A1930.993CB59B@planet.nl>
I've retrieved using LWP: a html file from a web-server. Before being
usefull the contents has to be changed/parsed. I've experience with
regexes but now I'm baffled. Have tried quite a few things.
Basicaly, the following has to be done. If an url is relative
(pics/menu.gif or relative to the root eg /content/pics/menu.gif) it has
to be changed into http://www.mysite.com/pics/menu.gif and
http://www.mysite.com/content/pics/menu.gif. In the latter case simply
concatenating http://www.mysite.com and /content/pics/menu.gif isn't
good because .com//content/ isn't valid html. Problem is that absolute
urls like "http://www.somehting.com/.....gif" have to be left alone.
The urls are used when using src= and href=. Of course src=url,
src="url" and src='url' and src = url are valid html which can be
found in the retrieved files.
I'm confident the solution is elegant and simple but I currently don't
see the solution.
Any help is very much appreciated.
JB.
------------------------------
Date: 28 Jun 2000 16:50:06 GMT
From: <arnet@hpcvplnx.cv.hp.com>
Subject: Re: Help: regex for changing NON-absolute urls in a html file.
Message-Id: <8jdabu$els$1@hpcvnews.cv.hp.com>
In comp.lang.perl Jan Bessels <jbessels@planet.nl> wrote:
> Basicaly, the following has to be done. If an url is relative
> (pics/menu.gif or relative to the root eg /content/pics/menu.gif) it has
> to be changed into http://www.mysite.com/pics/menu.gif and
> http://www.mysite.com/content/pics/menu.gif. In the latter case simply
> concatenating http://www.mysite.com and /content/pics/menu.gif isn't
> good because .com//content/ isn't valid html. Problem is that absolute
> urls like "http://www.somehting.com/.....gif" have to be left alone.
> The urls are used when using src= and href=. Of course src=url,
> src="url" and src='url' and src = url are valid html which can be
> found in the retrieved files.
If you could explain the ".com//content/ isn't valid html" problem a
bit more I might be able to help. I've written several scripts that
do more or less what you want, but they simply look for references
without the "http://..." part and add it. I don't understand your
comment about concatenation.
--arne
DISCLAIMER: These opinions and statements are those of the author and
do not represent any views or positions of the Hewlett-Packard Co.
------------------------------
Date: Wed, 28 Jun 2000 16:54:48 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Help: regex for changing NON-absolute urls in a html file.
Message-Id: <3981B9C7.503842BE@rochester.rr.com>
Jan Bessels wrote:
>
> I've retrieved using LWP: a html file from a web-server. Before being
> usefull the contents has to be changed/parsed. I've experience with
> regexes but now I'm baffled. Have tried quite a few things.
>
> Basicaly, the following has to be done. If an url is relative
> (pics/menu.gif or relative to the root eg /content/pics/menu.gif) it has
> to be changed into http://www.mysite.com/pics/menu.gif and
> http://www.mysite.com/content/pics/menu.gif. In the latter case simply
> concatenating http://www.mysite.com and /content/pics/menu.gif isn't
> good because .com//content/ isn't valid html. Problem is that absolute
> urls like "http://www.somehting.com/.....gif" have to be left alone.
> The urls are used when using src= and href=. Of course src=url,
> src="url" and src='url' and src = url are valid html which can be
> found in the retrieved files.
>
> I'm confident the solution is elegant and simple but I currently don't
> see the solution.
> Any help is very much appreciated.
>
> JB.
You may find the URI module and its relations to be of assistance.
--
Bob Walton
------------------------------
Date: Wed, 28 Jun 2000 17:26:55 GMT
From: preetham@my-deja.com
Subject: Re: Help: regex for changing NON-absolute urls in a html file.
Message-Id: <8jdcg5$jom$1@nnrp1.deja.com>
In article <3981B9C7.503842BE@rochester.rr.com>,
Bob Walton <bwalton@rochester.rr.com> wrote:
> Jan Bessels wrote:
> >
> > I've retrieved using LWP: a html file from a web-server. Before
being
> > usefull the contents has to be changed/parsed. I've experience with
> > regexes but now I'm baffled. Have tried quite a few things.
> >
> > Basicaly, the following has to be done. If an url is relative
> > (pics/menu.gif or relative to the root eg /content/pics/menu.gif)
it has
> > to be changed into http://www.mysite.com/pics/menu.gif and
> > http://www.mysite.com/content/pics/menu.gif. In the latter case
simply
I'm using the following :
I get an response object by using
$MyAgent= new LWP::UserAgent;
then
$Response=$MyAgent->request(..
then
$base=$Respose->base;
u get the base address here then u use a URI::URL object
$u=url($rel_path,$base);
u get the absolute path using
$u->abs;
> > concatenating http://www.mysite.com and /content/pics/menu.gif isn't
> > good because .com//content/ isn't valid html. Problem is that
absolute
> > urls like "http://www.somehting.com/.....gif" have to be left alone.
> > The urls are used when using src= and href=. Of course src=url,
> > src="url" and src='url' and src = url are valid html which can be
> > found in the retrieved files.
> >
> > I'm confident the solution is elegant and simple but I currently
don't
> > see the solution.
> > Any help is very much appreciated.
> >
> > JB.
> You may find the URI module and its relations to be of assistance.
> --
> Bob Walton
>
--
(--------------------------) {((((((
( Preetham.M ) /_ _ )
( preetham@rocketmail.com ) ( . . )
( What a life !!! ) ( / )
(----------------------------------oOOo------------oOOo---)
(---------------------------------------------------------)
(---------------------------------------------------------)
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 28 Jun 2000 08:46:26 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: How to access all the files in a dir including its sub dir?
Message-Id: <m1ya3pvmel.fsf@halfdome.holdit.com>
>>>>> "A" == A J Norman <nja@le.ac.uk> writes:
A> Look at the script below. The show_files() function is called
A> recursively whenever it finds a directory.
Please stop posting stuff like this. It breaks in the face of errors
and symlinks, both of which happen enough times that this code is good
only on a good day.
"use File::Find". It comes with Perl. It does what you need.
Please stop with the cargo-cult programming.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Wed, 28 Jun 2000 17:07:35 GMT
From: Francis Litterio <franl-removethis@world.omitthis.std.com>
Subject: Re: how to count number of line in a file ?
Message-Id: <m33dlxivjc.fsf@franl.andover.net>
amitr@w-o-i.com writes:
> "W Kemp" <bill.kemp@wire2.com> wrote:
> > amitr@w-o-i.com wrote in message <8jc8dg$o69$1@nnrp1.deja.com>...
> > >> Would someone please help me the best way to count
> > >> the number of lines in a file ?
> > >my $no_of_lines = `wc -l "$path/$filename" | awk '{ print $1 }'`;
> > open a FILE, then:-
> >
> > $i=0;
> > while(<FILE>){$i++}
> But the person, already telling that he is dealing with a large files.
> I think opening a file, counting the lines in a loop should take some
> time. It wont be a good idea afterall.
And how does "wc -l filename" avoid opening the file and reading all the
lines in a loop?
To count lines in a file (under UNIX or Windows filesystems), you _must_
open the file, read the entire file, and count the number of
line-termination character sequences it contains.
> So,
> if he is using unix(like) system he should go for what I have suggested.
Your solution offers no speed advantage (maybe a slight speed
disadvantage thanks to spawning three processes instead of zero
processes). As well, your solution has a distict portability
disadvantage.
--
Francis Litterio
franl-removethis@world.std.omit-this.com
PGP public keys available on keyservers.
------------------------------
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 3501
**************************************