[19126] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 1321 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jul 18 00:05:46 2001

Date: Tue, 17 Jul 2001 21:05:10 -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: <995429109-v10-i1321@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 17 Jul 2001     Volume: 10 Number: 1321

Today's topics:
    Re: Advice REQ for newbie (mc)
    Re: All computers in world MUST sync with ATOMIC clock  <wyzelli@yahoo.com>
    Re: All computers in world MUST sync with ATOMIC clock  <avek_nospam_@videotron.ca>
    Re: chomp (mc)
        Debugger -- ActivePerl / Perl Builder / Perltk / (Joe Chung)
    Re: error making Archive::Zip <ayamanita.nospam@bigfoot.com>
    Re: file date <goldbb2@earthlink.net>
    Re: File tutorial? <goldbb2@earthlink.net>
    Re: File tutorial? (mc)
    Re: Graph.pm example <william-news-102374@scissor.com>
    Re: How do I get information from a web page <dbe@wgn.net>
    Re: How to determine email quoting & level <sun_tong@users.sourceforge.net>
    Re: Is ActivePerl a good debugger? <schabernackel@hotmail.com>
        LWP and Capitalone <mail@enricong.com>
    Re: Obtaining remote users ip (Alan Barclay)
    Re: Perl or PHP? <schabernackel@hotmail.com>
        perl regular expression grammar (Alan Oursland)
    Re: Pull ng posts behind firewall <whataman@home.com>
    Re: Replacing a specific line (Tad McClellan)
        skipping a duplicate (Troy Lachinski)
    Re: sortlen -- filter to sort text by line length <goldbb2@earthlink.net>
    Re: Ternary Conditional Operator Question <dbe@wgn.net>
    Re: Ternary Conditional Operator Question <wyzelli@yahoo.com>
        The /e switch for regexp <sun_tong@users.sourceforge.net>
    Re: The /e switch for regexp <ayamanita.nospam@bigfoot.com>
    Re: The /e switch for regexp (Steven Smolinski)
    Re: The /e switch for regexp (Jay Tilton)
    Re: Why is var using same memory location <goldbb2@earthlink.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Wed, 18 Jul 2001 03:57:43 GMT
From: nospam@home.com (mc)
Subject: Re: Advice REQ for newbie
Message-Id: <3b550832.388188354@news>

On Mon, 16 Jul 2001 19:49:02 +0100, "Pete" <bloke6789@hotmail.com>
wrote:

>
>"Tad McClellan" <tadmc@augustmail.com> wrote in message
>news:slrn9l5uqe.5ld.tadmc@tadmc26.august.net...
>>
>> [ Please do not send stealth Cc's. It makes people angry. ]
>>
>Thanks for your forbearance. I obviously can't cut the mustard at this
>group - I can't even work out how to get to the FAQs, I only seem to get
>news in Outlook Expres, not in the browser. As for stealth, I wouldn't know
>it if it crept up on me!
>
>I can write a java program to do what I want, I just thought perl would be a
>better choice. I'll keep at it.

Assuming that's all you want to do, you can do this --
with results more like you expected -- from the command line:

perl -i -pe 's/^\s*\d{1,2}$//'  FILES

This would print the output directly back into your file.

mc


------------------------------

Date: Wed, 18 Jul 2001 12:45:42 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: All computers in world MUST sync with ATOMIC clock before 12:00 AM  21July 2001
Message-Id: <%5757.13$0b5.1233@vic.nntp.telstra.net>

"alavoor" <alavoor@yahoo.com> wrote in message
news:3B54F753.7B166886@yahoo.com...
>
> All computers in the world MUST sync with ATOMIC clock before 12:00 AM
> 21 July 2001!!!

Or what?

> hello:

hello?

> You must sync your PC's date and time with Cesium Atomic clock.

I must?

> Use this very small and tiny program written in PHP.

I sense a sales pitch.

> Do you know that Cesium Atomic clock located in Boulder, Colarado, USA
> is the world's most accurate clock!! It does not lose or gain one second

Indeed.  More accurate than any other Cesium Atomic clock?

> even after running for 25 MILLION YEARS!!! This clock is the official
> time USA and for the world.

Gee who was around to start it back then?

Kinda reminds me of the museum tour guide who claimed a dinosaur skeleton to
be 25 Million and 10 years old.  The tourists were flabbergasted and asked
how the dating could be achieved with such accuracy.  The guide replied
'Well, it was 25 Million years old when I got here, and I've been here for
10 years....'

<snip of drivel.>

Wyzelli
--
push@x,$_ for(a..z);push@x,' ';
@z='092018192600131419070417261504171126070002100417'=~/(..)/g;
foreach $y(@z){$_.=$x[$y]}y/jp/JP/;print;




------------------------------

Date: Wed, 18 Jul 2001 00:02:13 -0400
From: "AV" <avek_nospam_@videotron.ca>
Subject: Re: All computers in world MUST sync with ATOMIC clock before 12:00 AM  21July 2001
Message-Id: <2U757.21616$mc4.1899813@weber.videotron.net>

 ...There was nothing so VERY remarkable in that; nor did Alice think it so
VERY much out of the way to hear the Rabbit say to itself, `Oh dear! Oh
dear! I shall be late!' ....

C.L.Dodgson (via AlexV)

"alavoor" <alavoor@yahoo.com> wrote in message
news:3B54F753.7B166886@yahoo.com...
>
> All computers in the world MUST sync with ATOMIC clock before 12:00 AM
> 21 July 2001!!!
>
> hello:
> You must sync your PC's date and time with Cesium Atomic clock.
>
> Use this very small and tiny program written in PHP.
>
> Do you know that Cesium Atomic clock located in Boulder, Colarado, USA
> is the world's most accurate clock!! It does not lose or gain one second
>
> even after running for 25 MILLION YEARS!!! This clock is the official
> time USA and for the world.
>
> There are also similar Atomic clocks in France, UK, Germany and Japan.
>
> This program runs on MS Windows 95/98/NT/2000/XP/ME and MS Windows 3.11.
>
> This program also runs on all flavors of Unix and Linux and Apple Mac.
>
> Please download the program from:
>  http://phpclasses.upperdesign.com/browse.html/package/285
>




------------------------------

Date: Wed, 18 Jul 2001 03:46:34 GMT
From: nospam@home.com (mc)
Subject: Re: chomp
Message-Id: <3b5505b4.387550443@news>

On 15 Jul 2001 20:34:47 -0700, derelixir@my-deja.com (derelixir)
wrote:

>I've already tried - $/="\r\n"; but it doesn't chomp as well.
>Is there a way I could identify what character is actually used to
>terminate line in my text file?
>I'm using UNIX and reading the text file also from UNIX.

You're using UNIX, right?  Then it's a simple matter to look 
at your file with the od command.  Try "od -c" or "od -cd" 
piped to less.

mc


------------------------------

Date: Wed, 18 Jul 2001 00:51:40 GMT
From: m_010@yahoo.com (Joe Chung)
Subject: Debugger -- ActivePerl / Perl Builder / Perltk /
Message-Id: <3b54dc5a.112633906@enews.newsguy.com>

I found 3 popular perl debugger, which one is the best? 

I perfer writing perl code on windows and run on Unix. I wonder if
perl code is portable across different platform, like Java code?

Does ActivePerl come with the standard perl interpreter?  so that I
can write code using ActivePerl,  then run it on unix's perl.  Any
compatiblity problem?

Thanks.


------------------------------

Date: Wed, 18 Jul 2001 02:15:57 GMT
From: Akira Yamanita <ayamanita.nospam@bigfoot.com>
Subject: Re: error making Archive::Zip
Message-Id: <3B54F161.7F79E32C@bigfoot.com>

John DeRama wrote:
> 
> Hey I don't know the answer to your problem, but can you help me with
> finding modules like you use? For example the archive tar (or maybe zip, ace
> or rar) modules? Where can I find other perl modules?

http://www.cpan.org/

Read the documentation:
perldoc -q modules


------------------------------

Date: Tue, 17 Jul 2001 23:40:33 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: file date
Message-Id: <3B550531.13CA6BDE@earthlink.net>

Scaramouche wrote:
> 
> i currently have a perl script that uses opendir and readdir for a
> listing of files within a certain directory.  however, this just
> returns the file name(s) that are currently present when i run the
> script.  is there a way of getting the file date also?  this script
> returns back the number of users logged into a certain db so i need to
> know just when they logged in. i'm trying to stay away from using
> system() calls such as dir.
> the script runs on a winnt box and the dir it reads is (i believe)
> ntfs.
[code snipped]
#! perl -w
use strict;
use POSIX qw(strftime);

system("cls");

print strftime( "\t[ %a %b/%d/%Y:%r ]\n\n", localtime() );

my $directory = "z:/some/dir";

foreach (map "$directory/$_", do {
	opendir my $dh, $directory
		or die "Couldn't opendir $directory: $!\n";
	readdir $dh }) {
	my @s = stat or (warn("Couldn't stat $_: $!\n"), next);
	next if -d _;
	print;
	print strftime( ": %a %b/%d/%Y:%r\n", localtime($a[9]) );
}

-- 
The longer a man is wrong, the surer he is that he's right.


------------------------------

Date: Tue, 17 Jul 2001 22:58:42 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: File tutorial?
Message-Id: <3B54FB62.36215643@earthlink.net>

millside wrote:
> 
> Hi,
> Anyone know of an online tutorial?
> I'm struggling to create a sub to prevent duplicates in my .txt file
> (used for subscribed email addresses)

There are two common ways to do this, both of which use a hash:

This method uses alot of memory, and doesn't print anything out until
it's read everything in:

#! perl -w
use strict;
my %addrs;
/(\S*)/ && $addrs{$1} = $_ while( <> );
print values %addrs;
__END__

This method prints every item which it hasn't yet seen out as soon as
it's got it... it begins printing right away, and doesn't wait until
everything's been read in.

#! perl -w
use strict;
my %seen;
print unless (/(\S*)/ && $seen{$1}++) while( <> );
__END__

-- 
The longer a man is wrong, the surer he is that he's right.


------------------------------

Date: Wed, 18 Jul 2001 04:04:26 GMT
From: nospam@home.com (mc)
Subject: Re: File tutorial?
Message-Id: <3b550a6a.388756894@news>

On Tue, 17 Jul 2001 19:05:22 GMT, "millside"
<millettNOSPAM@lblueyonder.co.uk> wrote:

>Hi,
>Anyone know of an online tutorial?
>I'm struggling to create a sub to prevent duplicates in my .txt file (used
>for subscribed email addresses)
>Thanks
>--
>millside

Here's how you do it:

sort file | uniq > tmpfile; mv tmpfile file

And in perl:

system("sort file | uniq > tmpfile; mv tmpfile file");

:-P


------------------------------

Date: Tue, 17 Jul 2001 21:00:17 -0700
From: William Pietri <william-news-102374@scissor.com>
Subject: Re: Graph.pm example
Message-Id: <tla2eicbaqvma2@corp.supernews.com>

James Heneghan wrote:
>  Hi All,
> 
> I downloaded Graph.pm and tried to run the example.
> 
>[...]
>>Can't locate object method "newFromGif" via package "GD::Image" at
>> /usr/lib/perl5/site_perl/5.6.0/i386-linux/Graph.pm line 761.
> 
> I've tried to locate this method too but its not there!
> 
> Anyone know the solution?

My recollection is that GD, thanks to patent threats from Unisys, removed 
all GIF support. Certainly, there is none now:

    http://www.boutell.com/gd/

And although older versions (like 1.18) had these calls, the current 
version (1.33) does not. I think GIFs have been unsupported for a year or 
two.

Perhaps the module you're trying to use is out of date?

William


------------------------------

Date: Tue, 17 Jul 2001 19:19:11 -0700
From: "$Bill Luebkert" <dbe@wgn.net>
Subject: Re: How do I get information from a web page
Message-Id: <3B54F21F.3A0AC391@wgn.net>

Bubba wrote:
> 
> I am looking for a simple perl script that would allow me to get the
> contents of a web page and print it to a file.  Anyone know if this is
> possible?

The LWP modules will handle this easily.

use LWP::Simple;

my $url = 'http://www.domain.com/xyz.html';
my $content = get ($url);
 ...
etc.

-- 
  ,-/-  __      _  _         $Bill Luebkert   ICQ=14439852
 (_/   /  )    // //       DBE Collectibles   Mailto:dbe@todbe.com 
  / ) /--<  o // //      http://dbecoll.webjump.com/ (Free site for Perl)
-/-' /___/_<_</_</_     Castle of Medieval Myth & Magic http://www.todbe.com/


------------------------------

Date: 17 Jul 2001 23:28:59 -0300
From: * Tong * <sun_tong@users.sourceforge.net>
Subject: Re: How to determine email quoting & level
Message-Id: <sa8ae239dhw.fsf@suntong.personal.users.sourceforge.net>

tadmc@augustmail.com (Tad McClellan) writes:

> * Tong * <sun_tong@users.sourceforge.net> wrote:
> 
> >I'm trying to use the following RE to identify quote email lines:
> 
> 
> I'd do it the way Damian did it:
> 
> http://search.cpan.org/doc/DCONWAY/Text-Autoformat-1.04/lib/Text/Autoformat.pm

GREAT! Thanks a lot Tad! You are really helpful!

-- 
Tong (remove underscore(s) to reply)
  *niX Power Tools Project: http://xpt.sourceforge.net/
  - All free contribution & collection


------------------------------

Date: Wed, 18 Jul 2001 01:51:28 GMT
From: Haber Schabernackel <schabernackel@hotmail.com>
Subject: Re: Is ActivePerl a good debugger?
Message-Id: <1105_995421470@f3bpc14>

On Tue, 17 Jul 2001 22:57:21 GMT, m_010@yahoo.com (Joe Chung) wrote:
> Is ActivePerl a good perl debugger?  compare to the standard unix perl
> debugger like ptkdb or perl -d

The ActivePerl debugger _is_ 'perl -d'.
But ActiveState, the company that distributes ActivePerl,
have made some other software that have visualizes perl
debugging. That is: 
Perl Development Kit and Visual Perl (beta)

 
> ActivePerl looks more user friendly.
 
'beginner friendly' perhaps.
Often not the same as 'user friendly'.




------------------------------

Date: Tue, 17 Jul 2001 21:08:23 -0500
From: "Enrico Ng" <mail@enricong.com>
Subject: LWP and Capitalone
Message-Id: <9j2r3k$pj5$1@info1.fnal.gov>

I am trying to use LWP to access my account info a CapitalOne.
The problem is that they are weird in their process for loggin in.
first, they check for two cookies that are set via javascrict.  but it
seems to be set to random numbers.
then they have some chach to see if your browswer is cookie enabled, but
I'm not sure how.
can someone help me out.

https://service.capitalone.com/cgi/Home?Login
is the page that uses javascript to redirect you.
it sets two cookies.  and checks to see if your cookie enabled.

htts://service.capitalone.com/ndconfig.nd/CapOneIAS/pgLogin
this is the login page.
and the form even has a random number.

I tried the following code:
use LWP::UserAgent;
use Crypt::SSLeay;
use HTTP::Cookies;
#use LWP::Debug '+';
$ua = new LWP::UserAgent;
$cookie_jar=new HTTP::Cookies;
$ua->cookie_jar($cookie_jar);
my $req = new HTTP::Request POST =>
'https://service.capitalone.com/cgi/Home?Login';
my $res = $ua->request($req);
print ($cookie_jar->as_string());
my $req = new HTTP::Request POST =>
'https://service.capitalone.com/ndconfig.nd/CapOneIAS/pgLogin';
$req->content_type('application/x-www-form-urlencoded');
my $res = $ua->request($req);
print $res->content();



--
--
Enrico Ng <mail@enricong.com>




------------------------------

Date: 18 Jul 2001 02:43:44 GMT
From: gorilla@elaine.furryape.com (Alan Barclay)
Subject: Re: Obtaining remote users ip
Message-Id: <995424191.114281@elaine.furryape.com>

In article <srj66csm32i.fsf@w3proj1.ze.tu-muenchen.de>,
Walter Hafner  <hafner-usenet@ze.tu-muenchen.de> wrote:
>Hiho!
>
>Remember, that most Proxies rewrite the IP address and send the original

s/most/some/;

The original client might not even have an IP address, and even if it
does, it may be a private address, which has no meaning outside
of a private network.

>address in an X-Forwarded-For header. I use (for logging purposes in a
>Apache mod_perl authentification handler):



------------------------------

Date: Wed, 18 Jul 2001 01:40:52 GMT
From: Haber Schabernackel <schabernackel@hotmail.com>
Subject: Re: Perl or PHP?
Message-Id: <1104_995420834@f3bpc14>

On Wed, 18 Jul 2001 09:41:52 +0930, "Martin Jericho" <mjericho.nospam@gmx.net> wrote:
> ----- Original Message -----
>>...
> > Perl
> > is rapidly replacing bash/sh shell scripts as the main scripting language
> > used to maintain Linux computers.

about time!

> 
> Has something been done about the problem that the perl interpreter is too
> "fat"?  Is it loaded into common memory now or some other trick?

Well, on seven year old computers todays perl 5 would perhaps be fat.
But on a 350 mhz linux-PC, two years old, it is very "slim". The fact
that the following gives an elapsed time of two houndreds of a
second proves that imo: time perl -e 'print for 1..111'
This perl-process use slightly less than 1 mb, according to the 'top'
program. (Probably using shared libraries thou). Simple bash-processes
uses more!
 
> > Other languages to consider for use on web servers are Python, Ruby and
> > Java (for all platforms) and VisualBasic Script (for Microsoft IIS ASP
> > pages).
> (snip)
> 
> The basic thrust of my question was to find out (from a perl advocate's
> perception) why PHP was even invented when it seems that they are so
> similar, perl can do everything it can, and has been around for so much
> longer.

Someone wanted to make money on the books they wrote about php?
 
> Any comments from someone who knows both?
> 





------------------------------

Date: 17 Jul 2001 23:28:53 -0400
From: alan@oursland.net (Alan Oursland)
Subject: perl regular expression grammar
Message-Id: <01-07-080@comp.compilers>
Keywords: syntax

I've been looking for a complete perl 5 regular expression grammar
and, having been unsuccessful in my search, have attempted to write
one myself. I was wondering if anyone could help me find any errors in
it (excluding grammar syntax errors). I've left out embedded modifiers
from the grammar -- I'm not sure how they fit into the grammar. I've
also skimmed over the non-meta character production. One area I am
confused is the "\c[" control character (described at
http://www.perldoc.com/perl5.6/pod/perlre.html). How does this work?

Alan Oursland

Here is the grammar:
<re>		::= <union>
<union>		::= <concat>"|"<union>	| <concat>
<concat>	::= <quant><concat>	| <quant>
<quant>		::= <group>"*"		| <group>"+"	| <group>"?"	| <group>"{"<bound>"}"	| <group>
<group>		::= "("<re>")"		| <term>
<term>		::= "."			| "$"		| "^"		| <char>			| <set>
<bound>	::= <num>		| <num>","	| <num>","<num>
<char>		::= <non-meta>	| "\"<escaped>
<non-meta>	::= any non-meta char
<escaped>	::= <meta>|<control>|<special>|<assert>
<meta>		::= "."|"^"|"$"|"?"|"*"|"+"|"|"|"["|"("|")"|"\"|"{"
<control>	::= "t"|"n"|"r"|"f"|"a"|"e"|"l"|"u"|"L"|"U"|"E"|"Q"
<special>	::= <backoctal>|<hexchar>|<controlchar>|<class>
<assert>	::= "b"|"B"|"A"|"z"|"Z"|"G"
<backoctal>	::= <digit> | <digit><digit> | "0"<oct><oct> | "+" | "&" | "`" | "'"
<hexchar>	::= "x"<hex><hex> | "x{"<hex><hex><hex><hex>"}"
<controlchar>	::= "c["
<namedchar>	::= "N{"<name>"}"
<class>		::= "w"|"W"|"s"|"S"|"d"|"D"|"X"|"C" |"p"<name>|"P"<name>|"[:"<posixclass>":]"|"[:^"<posixclass>":]"
<posixclass>	::= "alpha"|"alnum"|"ascii"|"cntrl"|"digit"|"graph"|"lower"|"print"|"punct"|"space"|"upper"|"word"|"xdigit"
<name>		::= <unicodeclass>
<unicodeclass>	::= "IsAlpha"|"IsAlnum"|"IsASCII"|"IsCntrl"|"IsDigit"|"IsGraph"|"IsLower"|"IsPrint"|"IsPunct"|"IsSpace"|"IsUpper"|"IsWord"|"IsXDigit"
<set>		::= "[" <set-items> "]" | "[^" <set-items> "]"
<set-items>	::= <set-item> | <set-item> <set-items>
<set-item>	::= <range> | <char>
<range>		::= <char> "-" <char>
<num>		::= <digit><num> | <digit>
<oct>		::= "0"|"1"|"2"|"3"|"4"|"5"|"6"|"7"
<digit>		::= "0"|"1"|"2"|"3"|"4"|"5"|"6"|"7"|"8"|"9"
<hex>		::= "0"|"1"|"2"|"3"|"4"|"5"|"6"|"7"|"8"|"9"|"a"|"b"|"c"|"d"|"e"|"f"|"A"|"B"|"C"|"D"|"E"|"F"
<mod>		::= "\i"|"\m"|"\s"|"\x"



------------------------------

Date: Wed, 18 Jul 2001 02:00:10 GMT
From: "What A Man !" <whataman@home.com>
Subject: Re: Pull ng posts behind firewall
Message-Id: <3B54EDA8.543DDA8C@home.com>

Philip Newton wrote:
> 
> On Tue, 17 Jul 2001 01:36:58 -0500 (CDT), dennis100@webtv.net (BUCK
> NAKED1) wrote:
> 
> > Is there a way in Perl to download newsgroup posts behind a firewall, if
> > the firewall is my own ISP?
> 
> That depends on the nature of the firewall and how it is configured (for
> example, does it allow traffic to the NNTP port to pass).
> 
> > For example, I want to write a perl newsreader that will get all of the
> > posts from alt.discuss.computer (which is a webtv only discussion group).
> >
> > Will the NNTP module do this?
> 
> I think your question is "can I use the Net::NNTP module on a machine
> that's connected to the net to access the webtv-only newsgroup
> alt.discuss.computer?".
> 
> You need to find a news server that carries that newsgroup and that
> allows you to read. If you have such a server, and can connect to it
> with Net::NNTP, then you can use it.
> 
Thanks. How do I find out if a news service can connect to my newsgroup?

> If, say, only news.webtv.net (or whatever) carries that group, and it
> restricts access by IP address to WebTV devices, then Net::NNTP from a
> non-WebTV device would not be able to access it. If acess is granted by
> username/password, you could use Net::NNTP and authenticate with your
> Net::NNTP username/password combination.
> 
> More knowledge of your setup is required before we can give a useful
> answer.
> 
> Cheers,
> Philip
> --

Hmmm... I don't really know how my firewalled ngs are accessed. I don't
have to enter a username or password, so I guess they go by my email
address.

I looked at a newsreader program named KWEST. Is this an easy newsgroup
reader or is it easier just to use the Net::NNTP module or MIT's
Mail2News Program?

Thanks for any direction.
 
As an aside, the reason I want to do this is because I want to read my
WebTV's ngs in text only, and WebTV only delivers them in HTML. And most
webtvers are obsessed with HTML, and put everything but the kitchen sink
in their posts... rams, bmps, pics of themselves, pics of mother, pics
of family, tons of HTML, etc., etc.
--Dennis


------------------------------

Date: Tue, 17 Jul 2001 19:09:38 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Replacing a specific line
Message-Id: <slrn9l9hdi.ad6.tadmc@tadmc26.august.net>

James Coupe <james@zephyr.org.uk> wrote:
>In message <3b54ace7.364814287@news>, mc <nospam@home.com> writes
>>>                      if ($memsettings[($i-1)] != '') {
>>>                              print FILE "$memsettings[($i-1)]\n";
>>>                      } else {
>>>                              print FILE "\n";
>>>                      }
>>>
>>
>>Is this your actual code?  You're missing a closing double quote in
>>the first line above but I'd think this wouldn't get past the
>>compiler.
>
>The first line has two single quotes.


And could have been written so that such misunderstanding
would not slow down maintenance:

   if ( length $memsettings[($i-1)] ) {
      ...


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: 17 Jul 2001 20:46:35 -0700
From: troylachinski@my-deja.com (Troy Lachinski)
Subject: skipping a duplicate
Message-Id: <f9490d56.0107171946.2b2c0c9d@posting.google.com>

Thanks in advance for any help given.  I would be happy with a point
in the right direction.  I have read the FAQ and several hundred
(somewhat) related posts.

I have a file that contains information about inventory items.  I need
to split this information into 2 files. The first file is a PLU file,
I will have one line of information in the [PLU FILE output] for each
line in the input file. The [PPY FILE output] is a secondary
information file where duplicates are not allowed.

sample input:
ABC123
BCD234
EFG345
HIJ123
KLM235
NOP234
QRS124

wanted output:

PLU FILE: 	PPY FILE:
ABC1		123
BCD2		234
EFG3		345
HIJ1		235
KLM4		124
NOP2
QRS5

 The PLU FILE will have the Alpha characters and the number of the
corresponding property file.

In this example:
123 = property 1
234 = property 2
345 = property 3
235 = property 4
124 = property 5

CODE snippet:

#!/perl -w
use strict;

print "CRS3000 exported PLU file name: ";		
chomp(my $infilename = <STDIN>);
print "CRS4000 PLU file name: ";
chomp(my $outfilename1 = <STDIN>);
print "CRS4000 PLU Property file name: ";
chomp(my $outfilename2 = <STDIN>);

open(OLD,$infilename) ||
	die "cannot open $infilename for reading: $!";
## optional test for overwrite...
die "will not overwrite $outfilename1" if -e $outfilename1;
open(PLU,">$outfilename1") ||
	die "cannot create $outfilename1: $!";
die "will not overwrite $outfilename2" if -e $outfilename2;
open(PROP,">$outfilename2") ||
	die "cannot create $outfilename2: $!";


my @PROP_val = ();
my $cnt = 0;
my $cnt2 = 0;
use Text::ParseWords;
MAINLOOP:
while(<OLD>) { # read a line from 3k file into $_
	$cnt++; 		# count the number of lines
	
## 	Read in the CRS3000 file
	$plu	 		= substr($_,    0,   3);
	$plu_prop		= substr($_,    3,   3);


		
			INNERLOOP:
			foreach $PROP_val (@PROP_val) {
				my $propNum = 0;
				$propNum++;
				{
				last if ($plu_prop eq $PROP_val); 
				}
			
			
			}
			push(@PROP_val, $plu_prop);	### These 2 lines should only be
executed if $plu_prop
			print PROP "$plu_prop\n";	###  does not exist in array @PROP_val		
			
			
		
			$cnt2++;

			print PLU  "$plu$propNum\n"; 	### This needs to happen for every
line of input
							
	

}
 

close(PLU);
close(PROP);
close(OLD) || die "close: $!";
print "$cnt2 of $cnt PLU's converted\n";


------------------------------

Date: Tue, 17 Jul 2001 22:15:44 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: sortlen -- filter to sort text by line length
Message-Id: <3B54F150.7408211B@earthlink.net>

Ren Maddox wrote:
> 
> On Tue, 17 Jul 2001, goldbb2@earthlink.net wrote:
> 
> > Ren Maddox wrote:
> >>
> >> On Fri, 13 Jul 2001, gbacon@HiWAAY.net wrote:
> >>
> >> [snipped sorting by length with ST or GRT]
> >>
> >> > A scalar already knows its length, so all the time and space used
> >> > in constructing, accessing, and stripping the augmented list is
> >> > wasted.
> >>
> >> Ack!  I thought that perhaps the GRT advantage of the built-in
> >> comparison would overcome this, but some quick benchmarking has not
> >> revealed that to be true.
> >
> > The basic sort (using the custom sort routine, doing a numeric
> > comparison on lengths) only compares a small, fixed, number of bytes
> > (depending on the size of a double), whereas the grt sort has to
> > compare (at least) 4 bytes, plus it continues on to look at the
> > string contents if the lengths are equal.  So if you grt sort
> > 100_000 strings all of length 50, it will do many many 54-byte
> > comparisons.  If you do the basic/custom sort, it will do many many
> > 8-byte comparisons (assuming doubles are 8 bytes).
> >
> > If strings are especially long, and many strings are all the same
> > length, you may get a significant benefit by adding a "stabilizer":
> >
> > my $stabilizer = 0;
> > print map { substr $_, 8 } sort map {
> >       pack 'NNa*', length, $stabilizer++, $_ } <>;
> 
> OK, that makes sense.  But it didn't pan out in my benchmarks.  Adding
> the stabilizer actually slowed the GRT down, and by an increasing
> margin as the size of the data set increased.  This was for strings of
> random length less than 10 consisting solely of "a"-s.

When strings are the same length, it has to compare the 'stabilizer'
items (which are 4 bytes).  If you leave out the stabilizer, it has to
compare the strings... whose lengths average 5.5, but most comparisons
end up comparing fewer than 5 bytes; when doing a comparison of
differing length strings, it simply compares up to the length of the
shorter string, which is less than 4 on average.

> As a further test, I tried this version that throws away the original
> data:
> 
> map { substr $_, 4 } sort map { pack 'N', length } <>;
> 
> While it is faster than the original version (unlike the stable GRT),
> it is still appreciably slower than the basic length sort.

Maybe if you used 'n' instead of 'N' it would be faster?

> The moral I'm taking from this is that the cost of a custom comparison
> is enough to make a difference between ST and GRT, but it is still
> dwarfed by the startup costs of both.  Only when the actual comparison
> routine itself is complex is there a benefit.
> 
> ... Or perhaps length based sorting is somehow optimized in current
> versions of Perl??

Its probably more like numeric comparisons are faster than string
comparisons... and also, perl might be able to tell that length()
returns an integer, not double, value, and is able to optomize to do
integer comparisons, which are faster still.  Hmm, I bet if you packed
the lengths with a 'C' template, GRT might be faster than the
basic/custom sort.

How does ST compare with GRT or with basic/custom sort?

Here's a possibility for a way to speed up ST...  Modern perls are able
to replace function of the forms:
	{ $a cmp $b }, { $b cmp $a }, { $a <=> $b }, { $b <=> $a }
With calls to builtin sort functions, so they can be just as fast as the
default sort.  If perl could be made to recognize when it is doing a
simple (cmp or <=>) comparison of $a->[0] to $b->[0], then we could make
the sort part of ST almost as fast as the default sort.  Possibly, perl
could also recognize when map is being called with { $_->[1] } as it's
sub, and replace that, too, with a special map.

-- 
The longer a man is wrong, the surer he is that he's right.


------------------------------

Date: Tue, 17 Jul 2001 18:07:44 -0700
From: "$Bill Luebkert" <dbe@wgn.net>
Subject: Re: Ternary Conditional Operator Question
Message-Id: <3B54E160.7704151F@wgn.net>

Jonathan Cunningham wrote:
> 
> Ok folks.
> 
> I'm usually pretty good at figuring this stuff out, but this one is
> really kicking my @$$.
> 
> I'm trying to see if $slash =~ m{/} is a match, and then I want to do
> a substitution on $_ depending on the outcome of the match.  I've
> tried a million ways to parenthesize, but no luck.
> 
> Could someone out there please let me know why this doesn't work:
> 
>     # @_     == ('d:/some/path');
>     # $slash == '';
> 
>     for(@_) {
>         $slash =~ m{/} ? s{\\}{/}g : s{/}{\\}g;
> 
>     # This doesn't work either...
>     #   ($slash =~ m{/}) ? s{\\}{/}g : s{/}{\\}g;
>     }
> 
> I'm hoping this is going to be a "duh" moment for me.

@_ = ('d:/some/path');

for (@_) {

	# either of these will do - there is no need for a ternary op

	s{/}{\\}g;
#	s{/}{\\}g if m{/};


}


-- 
  ,-/-  __      _  _         $Bill Luebkert   ICQ=14439852
 (_/   /  )    // //       DBE Collectibles   Mailto:dbe@todbe.com 
  / ) /--<  o // //      http://dbecoll.webjump.com/ (Free site for Perl)
-/-' /___/_<_</_</_     Castle of Medieval Myth & Magic http://www.todbe.com/


------------------------------

Date: Wed, 18 Jul 2001 10:59:39 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: Ternary Conditional Operator Question
Message-Id: <zy557.11$0b5.675@vic.nntp.telstra.net>

"Jonathan Cunningham" <dawfun@seanet.com> wrote in message
news:4d6fd5fc.0107171255.97784f7@posting.google.com...
> Ok folks.
>
> I'm usually pretty good at figuring this stuff out, but this one is
> really kicking my @$$.
>
> I'm trying to see if $slash =~ m{/} is a match, and then I want to do
> a substitution on $_ depending on the outcome of the match.  I've
> tried a million ways to parenthesize, but no luck.
>
> Could someone out there please let me know why this doesn't work:
>
>     # @_     == ('d:/some/path');
>     # $slash == '';
>
>     for(@_) {
>         $slash =~ m{/} ? s{\\}{/}g : s{/}{\\}g;
>
>     # This doesn't work either...
>     #   ($slash =~ m{/}) ? s{\\}{/}g : s{/}{\\}g;
>     }
>

I'll jump in and ask 'are you trying to solve the wrong problem?'

What are you trying to achieve?

You do realise that forward slashes are quite acceptable in a Perl program
on a Win32 box?

Wyzelli
--
($a,$b,$w,$t)=(' bottle',' of beer',' on the wall','Take one down, pass it
around');
for(reverse(1..100)){$s=($_!=1)?'s':'';$c.="$_$a$s$b$w\n$_$a$s$b\n$t\n";
$_--;$s=($_!=1)?'s':'';$c.="$_$a$s$b$w\n\n";}print"$c*hic*";





------------------------------

Date: 17 Jul 2001 23:32:29 -0300
From: * Tong * <sun_tong@users.sourceforge.net>
Subject: The /e switch for regexp
Message-Id: <sa866cr9dc2.fsf@suntong.personal.users.sourceforge.net>

Hi, 

I've been trying to locate the man page for the /e switch for
regexp, and I only find the following in perlre:

,-----
|        get into the habit of doing that, you get yourself into trouble if
|        you then add an /e modifier.
| 
|            s/(\d+)/ \1 + 1 /eg;        # causes warning under -w
`-----

That's the only place which covers about the /e switch, where can I
find more detail explanation? Thanks

PS, I'm using perl, version 5.005_03 built for i386-linux.

-- 
Tong (remove underscore(s) to reply)
  *niX Power Tools Project: http://xpt.sourceforge.net/
  - All free contribution & collection


------------------------------

Date: Wed, 18 Jul 2001 02:56:42 GMT
From: Akira Yamanita <ayamanita.nospam@bigfoot.com>
Subject: Re: The /e switch for regexp
Message-Id: <3B54FAED.76EE245E@bigfoot.com>

* Tong * wrote:
> 
> That's the only place which covers about the /e switch, where can I
> find more detail explanation? Thanks
> 
> PS, I'm using perl, version 5.005_03 built for i386-linux.

"perldoc -f s" mentions perldoc perlop so:
perldoc perlop


------------------------------

Date: Wed, 18 Jul 2001 03:06:48 GMT
From: steven.smolinski@sympatico.ca (Steven Smolinski)
Subject: Re: The /e switch for regexp
Message-Id: <c3757.24725$304.2939701@news20.bellglobal.com>

* Tong * <sun_tong@users.sourceforge.net> wrote:
> Hi, 
> 
> I've been trying to locate the man page for the /e switch for
> regexp, [...]
> 

In perlre, it only seems to cover some of the /x modifiers as they are
needed for other points.  But you do get this pointer in the paragraph
before it lists them:

   Modifiers that alter the way a regular expression is used by Perl are
   detailed in the Regexp Quote-Like Operators entry in the perlop man­
   page...

I suggest you follow the trail.  :-)

Steve
-- 
Steven Smolinski => http://arbiter.ca/


------------------------------

Date: Wed, 18 Jul 2001 03:15:15 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: The /e switch for regexp
Message-Id: <3b54fce8.136510549@news.erols.com>

On 17 Jul 2001 23:32:29 -0300, * Tong * <sun_tong@users.sourceforge.net>
wrote:

>I've been trying to locate the man page for the /e switch for
>regexp, and I only find the following in perlre:

The /e option (as well as others) is not part of any regex.  It is instead
part of the s/// operator.
perlop is the document you seek.


------------------------------

Date: Tue, 17 Jul 2001 22:34:35 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Why is var using same memory location
Message-Id: <3B54F5BB.6D123EBA@earthlink.net>

This has nothing to do with your problem, but is a suggestion for an
improvement:

Brian wrote:
[snip]
> Here is how I define this @tuxconfig array.
> 
> #CODE START
> my $x = 0;
> foreach (@TFs) {
>     $ENV{'TUXCONFIG'} = $_;
>     $tuxconfig[$x] = [`tmunloadcf`];
>     $x++;
> }
> #CODE END
> 
> tmunloadcf is a UNIX program that returns a few hundered lines of code
> and this will normally run twice (@TFs has two elements)

It's not perlish to use an index unless you *really* need it, for
example because you want to print out the index.  You would be better
off writing the above code as follows:

@tuxconfig = map {
        local $ENV{TUXCONFIG} = $_;
        [`tmunloadcf`];
    } @TFs;
Or:
foreach( @TFs ) {
    local $ENV{TUXCONFIG} = $_;
    push @tuxconfig, [`tmunloadcf`];
}



-- 
The longer a man is wrong, the surer he is that he's right.


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 1321
***************************************


home help back first fref pref prev next nref lref last post