[11209] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4809 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Feb 2 18:07:26 1999

Date: Tue, 2 Feb 99 15:00:22 -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           Tue, 2 Feb 1999     Volume: 8 Number: 4809

Today's topics:
    Re: "use" - packages loaded at runtime or compile time? (Abigail)
        [Q] CPAN module installs on Windows98 with ActivePerl a <wade@cs.ualberta.ca>
    Re: alternative perl NG for newbies? <andrewf@beausys.demon.co.uk>
    Re: are regular expression rationaly designed ? (Ilya Zakharevich)
        Avoiding rand (was Re: advertising script problem) dhosek@webley.com
    Re: beginner question (Martien Verbruggen)
        Checking links <gala@sonic.net>
    Re: code to recurse directories <ebohlman@netcom.com>
    Re: Comments in Perl code (Abigail)
    Re: DBI and Win32::ODBC - build or download???? <wade@cs.ualberta.ca>
    Re: Dial up Networking and PERL <mjw@metalink.net>
        FL - Ft. Lauderdale -  Senior Programmer/Analyst <msic@mediaone.net>
    Re: flock not working (Randal L. Schwartz)
    Re: grep and a variable (Bart Lateur)
    Re: Match Parens-More Perlish? (Damian Conway)
    Re: Match Parens-More Perlish? (Abigail)
    Re: Match Parens-More Perlish? (Abigail)
        Numeric Value <debot@xs4all.nl>
    Re: Numeric Value (Martien Verbruggen)
    Re: Perl Criticism [summary] birgitt@my-dejanews.com
    Re: Perl syntax ( URGENT ) (Martien Verbruggen)
    Re: Perl syntax ( URGENT ) (Abigail)
    Re: read an html from a url (Abigail)
    Re: Regex for e-mail addresses? (Larry Rosler)
    Re: Regex for e-mail addresses? (Abigail)
        Sockets still don't work at my place <martin.baur@mindpower.com>
    Re: Statistics for comp.lang.perl.misc (Abigail)
    Re: substituting keywords in a string (Martien Verbruggen)
    Re: UNIX 'tail' command in Perl?? <uri@ibnets.com>
    Re: UNIX 'tail' command in Perl?? (Sean McAfee)
    Re: Visual Perl? (I R A Aggie)
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: 2 Feb 1999 22:28:08 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: "use" - packages loaded at runtime or compile time?
Message-Id: <797u5o$qgp$1@client2.news.psi.net>

mizpoon@my-dejanews.com (mizpoon@my-dejanews.com) wrote on MCMLXXXI
September MCMXCIII in <URL:news:795pvv$2hj$1@nnrp1.dejanews.com>:
:: I need to use Date::Manip in one of my perl packages. As Date::Manip is a
:: large package, I only want it to get loaded when I need it, and not before. I
:: don't need it loaded at all times.
:: 
:: I was planning on wrapping the 'use Date::Manip' in a function.
:: 
:: Can someone tell me if this will ensure that the Date code will only get
:: loaded when this function is called? Or does the Perl interpreter whizz
:: through the code and load up all the use directives at compile time?

   sub function {
       require 'Date::Manip';
       Date::Manip -> import ();
       ...
   }



Abigail
-- 
perl5.004 -wMMath::BigInt -e'$^V=new Math::BigInt+qq;$^F$^W783$[$%9889$^F47$|8;
 .qq;8768$^W596577669$%$^W5$^F3364$[$^W$^F$|838747$[8889739$%$|$^F673$%$^W98$^F;
 .qq;76777$=56;;$^U=substr($]=>$|=>5)*(q.25..($^W=@^V))=>do{print+chr$^V%$^U;$^V
/=$^U}while$^V!=$^W'


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

Date: 02 Feb 1999 15:42:11 -0700
From: Wade Holst <wade@cs.ualberta.ca>
Subject: [Q] CPAN module installs on Windows98 with ActivePerl and Cygwin20.1
Message-Id: <r7yamgbf7g.fsf@rimbey.cs.ualberta.ca>


Greetings all,

I have a laptop with Windows 98, Active Perl, and Cygwin20.1.
I would like to use 'perl -MCPAN -e shell' and then start installing
the approx. 100 non-standard modules I find useful.  Unfortunately, the
Makefiles that are generated have SHELL='c:\com /c /x' or some such thing.
Since I'd like to use the UNIX-like capabilities of Cygwin, I'd like the
SHELL to be 'bash'.

So, how can I do this.  I suspect that I need to modify CPAN::Config.pm
to pass some flags to the perl Makefile.PL phase, and was hoping someone 
knows what to do.

Thanks in advance,

--
Wade Holst                wade@cs.ualberta.ca
University of Alberta     http://www.cs.ualberta.ca/~wade



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

Date: Tue, 2 Feb 1999 22:14:26 +0000
From: Andrew Fry <andrewf@beausys.demon.co.uk>
Subject: Re: alternative perl NG for newbies?
Message-Id: <OxisJAACj3t2EwbQ@beausys.demon.co.uk>

In article <vjs497.ho1.ln@magna.metronet.com>, Tad McClellan
<tadmc@metronet.com> writes
>23_skidoo (23_skidoo@geocities.com) wrote:
>: i know that there are a lot of very busy people in this newsgroup who
>: know more about perl than is probably healthy :) some of these people
>: seem to get 'snappish' when a newbie asks a question

My view precisely.

>
>   I think you have it wrong there.
>
>   A newbie asking a question isn't what sets folks off.
>
>   A newbie (or anyone, even a oldbie) asking a question that
>   is easy to find and clearly answered in files already
>   installed on your hard disk is what gets folks snappish.

As I have already said, take this to its logical conclusion and
one could, with some justification, answer 'RTFM' to 99.9% of all
questions.
This does rather presume that...
(a) newbies know what documentation exists, and know their way around it
(b) newbies have all the time in the world to read documentation
(c) the documentation will tell them precisely what they need to know
    (Come know ... anyone who knows technical documentation knows that
    that often isnt the case!)
(d) reading the numerous Perl books isnt enough

>
>   Of course, some folks get snappish when the relevant docs are
>   not easy to find or are not easy to understand.
>
>   Getting snappish in that case is Really Bad, but I believe it
>   to be the minority of the snappish replies.
>
>   Snappishness is inversely proportional to the (perceived)
>   amount of time the questioner spent trying to get the
>   question answered themselves.

It may irritate (some of) the experts who use this NG when newbies
post question which are so trivial and obvious and "uninteresting"
(...to quote one of the many condescending replies to myself a while
back) ... but I have to say that I am EQUALLY irritated by a response
which says nothing more that 'RTFM' (...especially when accompanied
by a hint of sarcasm).
I say: if you dont have anything more useful to say than this, then
DONT BOTHER SAYING ANYTHING!

>
>   eg:
>
>   When someone says:
>
>      "I have been using system() but it doesn't capture the output
>       from the command. How do I capture the output?"
>
>   Significant snappishness is likely to ensue since the description
>   of the system() function clearly says how to do it.
>
>   Folks are pretty darn sure that the poster did not spend even
>   60 seconds trying to find the answer in such a case...
>
>
>: perhaps
>: somewhere for the less experienced to swap ideas and help eachother out
>: would be a good idea. 
>
>: whatcha all think?
>
>
>   I think that this very same idea has been beaten to death.
>
>   A thread about this comes up about once a month or so...
>
>
>
>   If there are only newbies there, then you'll have the blind
>   leading the blind.
>
>   Folks meaning to help who give a bad answer without even knowing
>   that it is bad will create more problems rather than solve problems.
>
>   Good intentions do not equate to good results  :-)
>
>
>--
>    Tad McClellan                          SGML Consulting
>    tadmc@metronet.com                     Perl programming
>    Fort Worth, Texas

---
Andrew Fry
"Time flies like an arrow. Fruit flies like a banana". (Groucho Marx).


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

Date: 2 Feb 1999 21:19:08 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: are regular expression rationaly designed ?
Message-Id: <797q4c$b9b$1@mathserv.mps.ohio-state.edu>

[A complimentary Cc of this posting was sent to Ken Hirsch
<kenhirsch@myself.com>],
who wrote in article <797k96$ct2$1@oak.prod.itd.earthlink.net>:
> >Since Perl's RExen can do anything now (well, between 5.005 and
> >5.005_53 they could do *many* things), if the pattern is decidable,
> >they can do it.  They cannot recognize a correct C program which loops
> >forever.  ;-)

> Oh yeah, how about:
> 
> if (/\Qmain(){while(1);}/) {
>   print "This program loops forever!\n";
> }

This matches

#ifdef LINUX
main(){while(1);}
#else
main(){return 1;}
#endif

and does not match many other loopers.

Ilya


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

Date: Tue, 02 Feb 1999 22:09:36 GMT
From: dhosek@webley.com
Subject: Avoiding rand (was Re: advertising script problem)
Message-Id: <797t2n$tq6$1@nnrp1.dejanews.com>

In article <m3soco39ra.fsf@moiraine.dimensional.com>,
  Daniel Grisinger <dgris@moiraine.dimensional.com> wrote:
>     my $random_banner = $banner {int(rand(scalar keys %banner))};

Many places where rand is being used, particularly for web-based
applications, a (slightly) faster solution is to just do a modulo operation
on the time function. Take, for example, our banner selection project. Rather
than do rand($n), we could instead do (time % $n). Is it truly random? No. If
you're trying to do something like generate a pair of independent random
numbers, this approach won't work since we'll have something close to a fixed
interval between calls to time in the program (with slight variations
depending on things like load on the system where perl is running). But for
single random number applications, which includes every CGI scenario where
I've wanted a random number, this approach works great. You'd also want to
avoid this for apps run with cron or something similar. I'm not sure if the
time savings are sufficiently consequential to make this approach worthwhile.
Looking through the srand documentation (perldoc -f srand), it would appear
that in some ways this approach is superior to rand for CGI scripts.

-dh

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Tue, 02 Feb 1999 22:07:19 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: beginner question
Message-Id: <rGKt2.34$9v3.3501@nsw.nnrp.telstra.net>

[There _is_ no such group a comp.lang.perl, even if your news server
carries it. Inform your news admin. Removed.]

In article <36B739E4.4D7F7614@macdaddyusa.com>,
	dan <webmaster@macdaddyusa.com> writes:
> i must say thanks for your amazing, intuitive input. youve managed to waste all
> of our time. thanks a lot!

I must say that with your offtopic, unclear, unspecific question about
CGI and images, you've managed to waste all of our time.

Thanks a lot.

Maybe you should consider rephrasing your question in such a way that
it shows what you have already tried, what you have been looking at to
make it try, and maybe it should also be perl specific.

To quote your original question:

> lets say a user inputs  number in a form. how do i get the cgi
> script to make the length of the image the number the user put in?

Can you really honestly say that this question makes sense, is clearly
about perl, and shows that you have tried something yourself?

Questions that come up:

What form? Perl doesn't have forms.
What image? Which font? Where does the image go? 
What does all of this have to do with cgi anyway? 

Martien
-- 
Martien Verbruggen                  | 
Interactive Media Division          | If at first you don't succeed, try
Commercial Dynamics Pty. Ltd.       | again. Then quit; there's no use being
NSW, Australia                      | a damn fool about it.


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

Date: Tue, 2 Feb 1999 14:10:39 -0800
From: "Gala Grant" <gala@sonic.net>
Subject: Checking links
Message-Id: <797t2c$ki1$1@ultra.sonic.net>

I am trying to figure out how to use Perl to check links over the internet
without actually going to the site.  Can anyone help me out with any clues
as to how to do this?
Thanks,
Gala Grant




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

Date: Tue, 2 Feb 1999 20:38:57 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: code to recurse directories
Message-Id: <ebohlmanF6Jo0x.3no@netcom.com>

dturley@pobox.com wrote:
: After looking at my already well-worn "Perl Cookbook", I'm thinking, perhaps
: there should be an addition to the "read the faq" reply. How about "rtcb"?

The problem is that having a copy of the _Perl Cookbook_ isn't an
automatic consequence of having a non-broken Perl distribution the way
having a copy of the FAQ is.  It is, IMHO, contrary to the spirit of Perl
to treat the possession of a specific commercial product as a *necessary*
condition for using the language effectively, regardless of how useful (in
this case, *very*) that product is. 



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

Date: 2 Feb 1999 22:12:41 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Comments in Perl code
Message-Id: <797t8p$q4p$1@client2.news.psi.net>

Charles R. Thompson (design@raincloud-studios.com) wrote on MCMLXXX
September MCMXCIII in <URL:news:794p50$3ei@bgtnsc01.worldnet.att.net>:
[]                             I'm even so paranoid of it all that
[] I do stuff like this...
[] 
[] $CGI_PATH=$BASE_PATH.'cgi-bin/';
[] 
[] instead of this...
[] 
[] $CGI_PATH = $BASE_PATH . 'cgi-bin/';


You shouldn't be using Perl the way you are doing. If such micro
optimization is important to you, not even something like "mod_perl" is
appropriate for you. They least you need is a custom written server that
can do everything your CGI program can without the need of starting up
different processes. But you probably need a custom made OS, preferably
on custom made hardware, so you can get the very best performance.




Abigail
-- 
perl -we '$@="\145\143\150\157\040\042\112\165\163\164\040\141\156\157\164".
             "\150\145\162\040\120\145\162\154\040\110\141\143\153\145\162".
             "\042\040\076\040\057\144\145\166\057\164\164\171";`$@`'


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

Date: 02 Feb 1999 14:40:39 -0700
From: Wade Holst <wade@cs.ualberta.ca>
Subject: Re: DBI and Win32::ODBC - build or download????
Message-Id: <r7zp6wbi20.fsf@rimbey.cs.ualberta.ca>

Tom Williamson <tomw@action.cnchost.com> writes:

> I am working on a Perl project on Windows NT, trying to connect to
> MS-SQL Server.  (I know this is going over great with the Solaris and
> Oracle folks.)  Anyway, I have never worked with Perl before.  I have
> inherited some legacy code from the previous programmer which uses
> DBI::W32ODBC and Win32::ODBC modules, neither of which I have.

I just installed Win32::ODBC last week, and it is working very well.

Here is a quick summary:
  - The official webpage is at http://www.roth.net/odbc
     - The distributions are at ftp://ftp.roth.net/pub/ntperl/odbc
         - newest is ftp://ftp.roth.net/pub/ntperl/odbc/970208/
            - newest binary distribution is
                ftp://ftp.roth.net/pub/ntperl/odbc/970208/Bin/Win32_ODBC_Build_311.zip
              which is what you want.

  - Install ODBC (this is just a summary of the discussion in the README file
    that comes with the distribution).
       - extract the contents of Win32_ODBC_Build_311.zip anywhere you want.  For future
	 reference, I'll call this directory <ODBC_TMP>)
	  - go to your perl/lib directory
	     -  make Win32 if it doesn't exist (it didn't for my ActiveState, 
                installed 3 months ago)
	     -  make auto/Win32
	     -  copy <ODBC_TMP>/ODBC.pm to Win32
	     -  copy <ODBC_TMP>/odbc_311.pll to auto/Win32/odbc.pll


  - In order to test ODBC, there is a test script called 'test.pl' that comes
    with the distribution (i.e. <ODBC_TMP>/test.pl).  If you execute it, as in:
         - change to directory <ODBC_TMP>
         - perl test.pl
    it will test a variety of things.  The script is useful to get up to speed
    with how to use ODBC.  Sadly, the ODBC module itself does not have any
    embedded comments or pod documentation but there appears to be good
    documentation at http://www.roth.net/odbc/odbc.html - I haven't
    looked at the docs yet, as I found the test script quite
    informative on its own.

  - Just a quick note in case you are as unfamiliar with some of the 
    terminology as I was.  I haven't used ODBC before, so all I know about it
    is what I've learned from Win32::ODBC (that will be changing in the next
    week when I start using ODBC with oracle :-).  One important concept is
    that of a DSN (Data Source Name, I think). I assume that the concept
    of DSN's is not just a Windows-specific thing, but is instead something
    associated with ODBC.  From what I've gathered, a DSN is a conceptual 
    name that is associated with two things:
       1) a driver type (i.e. *.mdb, *.txt, etc.) and 
       2) a file of the appropriate type.  
    Once this association has been made, the ODBC module can use this name in
    order to open up a connection to the file using the appropriate ODBC driver
    (based on the driver type).  

         BTW, for any more knowledgeable person reading this, if the above 
        interpretation of DSNs is incorrect, please let me know.

    Thus, you cannot use ODBC until you have established one (or more) DSNs on
    which you want to work.  You can make DSNs two different ways.  Since I
    come from a UNIX background (and basically detest Windows), I prefer the
    second approach, but I'll list both :-)

      1) In Windows, go to StartMenu->Settings->Control Panel->32bit ODBC
           - selected "User DSN"  (for now - you can also make System DSNs, etc.)
           - select your desired driver (i.e. if you want to connect to an Access
             database, select the name left of 'Microsoft Access Driver (*.mdb)'
           - enter in the DSN you want to use (it is completely up to you - whatever
             is conceptually meaningful to you).
           - click the "Select" button and specify the path and name of the
             database file you want to associated with the DSN.
	   - click OK
           - exit ODBC window

       2) Thankfully, the ODBC module provides a programmatic mechanism for doing
          exactly the same thing, as demonstrated in the 'test.pl'
          script.  Since I am inherently lazy and automate everything
          (hence my contempt for Windows), I was quite happy about this.  I took
          the code in the 'test.pl' and wrote a general-purpose perl script for
          adding, removing and analyzing the existing DSNs.  I can send it to
          you if you are interested (unfortunately, I cannot do so right now
          because it is on a laptop machine sitting at home :-(

> I downloaded and installed Perl from ActiveState and have the basic Perl
> 5 modules.  The previous programmer on the project swears that DBI came
> with his Perl installation and that he was able to download and install
> a pre-built version of Win32::ODBC.

Win32::ODBC did not come with my ActiveState Perl.  Don't know if DBI did.

> I am already way behind on this project from having to come up to speed
> on Perl itself.   I am really hoping that I can download and install
> these modules from someplace, and avoid having to build them from
> scratch.  Is there anyone out there who can point me to a location where
> I can get pre-built DBI and Win32::ODBC??????  Or, to put it more
> bluntly - HELLLLLLP!

Hope this helps.

> Thanks - Tom
> tomw@action.cnchost.com


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

Date: Tue, 2 Feb 1999 16:02:17 -0500
From: "Matt Wiseman" <mjw@metalink.net>
Subject: Re: Dial up Networking and PERL
Message-Id: <797p1v$l6n$1@news0-alterdial.uu.net>

While I do see your point as far as the whole free speech thing goes, I
still stick to my guns. .
As for the alt.carpentry since 99% of people use hammers to hammer nails, I
would help him.  but at the same time if I was in line at the post office
and some guy was asking me if I knew how to unjam  a machine gun. . .I'm
going to assume he's not going after bambi and do everything in my power to
hinder his progress.  In the case of our DUN modifier, the only case that
I've seen that sort of code used is maliciously.  I did want to make sure he
was doing something legit. before I would consider helping him.  I don't
know, he may work for an ISP setting up a "Set up your account and switch
over Online!" kinda page, then by all means. ..however being as I don't see
that many benevolent uses for that application, I'm forced to question.
However, if he replies and gives some sort of legitiment use, by all means,
he has my kudos and support otherwise, www.evilporn.com will have to find
another way to sucker people.

gary robson <gary@altmedia.freeserve.co.uk> wrote in message
news:791jp8$81p$1@news4.svr.pol.co.uk...
>Can anybody tell me how to connect and hangup and windows Dial up
Networking
>account from perl.
>                    Cheers Gary
>
>
Steve Leibel wrote in message ...
>In article <793bus$l7l$1@news0-alterdial.uu.net>, "Matt Wiseman"
><webmaster@Shoggoth.org> wrote:
>
>> I've seen cases where a Porn Site uses javascript to cause a change to
the
>> default DUN file and causes the computer to redial the new 1-900 ISP I
don't
>> particularly find this sort of activity very moral. . .. what are you
>> planning on doing with this code??
>>
>
>Jeez Matt.  If the guy posted to alt.carpentry that he needed help
>hammering some nails, would you ding him because you once heard about
>somebody hitting someone over the head with a hammer?
>
>Hey some spammers use Perl to send out truckloads of spam, maybe we should
>all give up Perl.
>
>Steve L




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

Date: Tue, 02 Feb 1999 22:19:10 GMT
From: "TJ Johnson" <msic@mediaone.net>
Subject: FL - Ft. Lauderdale -  Senior Programmer/Analyst
Message-Id: <yRKt2.5418$Yq5.88178819@news2.pompano.net>

South Florida company seeks top-level Perl/CGI Gurus with superior
programming and systems analysis skills.  3+ years using Perl and CGI to
develop real world  web applications.  2+ years using Perl to access a
relational database (Sybase experience a plus).  2+ years using Unix,
knowledge of Apache Web Server, C, shell scripting.   Salary, benefits,
stock options, relocation help.

Send resume and correspondence to:
resume@mulliganservices.com
954-741-2106 fax
All inquiries will be kept confidential.  EOE




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

Date: 02 Feb 1999 13:39:37 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: flock not working
Message-Id: <m1yamgbi3q.fsf@halfdome.holdit.com>

>>>>> "Debbie" == Debbie Whitten <usenet-replies@rocketmail.com> writes:
[This is not right... you do not provide a valid email address <sigh>]

Debbie> $LOCK_SH = 1;
Debbie> $LOCK_EX = 2;
Debbie> $LOCK_NB = 3;
Debbie> $LOCK_UN = 4;

This is not right.  You can't just make these numbers up.

Debbie> while (($x = flock ("test.txt", $LOCK_EX))) { # supposedly wait

This is not right.  You cannot flock a filename... just a handle.

print "Just another Perl hacker,"

-- 
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me


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

Date: Tue, 02 Feb 1999 21:18:41 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: grep and a variable
Message-Id: <36b96aeb.2197823@news.skynet.be>

jimbob4334@my-dejanews.com wrote:

>@date - is an array with many dates including 1-12-98
>$var="1-12-98";
>@match = grep(/\Q$var\E/, @date);
>$no_of_mathces = $#match;
That should have been "@match" o nthe right side.

>I get $no_of_matches = -1
@matches == 0

No matches?

BTW I'd expect "11-12-98" to match as well. You might want to make your
regex more stringent.

	Bart.


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

Date: 2 Feb 1999 21:28:36 GMT
From: damian@cs.monash.edu.au (Damian Conway)
Subject: Re: Match Parens-More Perlish?
Message-Id: <797qm4$3lo$1@towncrier.cc.monash.edu.au>

frogsmock@my-dejanews.com wrote:

>I've been messing with approaches to matching arbitrarily nested constructs
>in Perl, and read with interest the various posts that said it couldn't be
>done using regular expressions.  Anyway, I'm fairly new to Perl, and I've
>come up with this approach for matching nested parentheses.  But it *feels*
>ugly, so . . .

You might want to check out the Text::Balanced module (on the CPAN). It's
designed to make just about any kind of bracket matching easy.

Damian


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

Date: 2 Feb 1999 22:42:34 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Match Parens-More Perlish?
Message-Id: <797v0q$qgp$2@client2.news.psi.net>

frogsmock@my-dejanews.com (frogsmock@my-dejanews.com) wrote on MCMLXXX
September MCMXCIII in <URL:news:7954v5$hmf$1@nnrp1.dejanews.com>:
$$ Folks,
$$ 
$$ I've been messing with approaches to matching arbitrarily nested constructs
$$ in Perl, and read with interest the various posts that said it couldn't be
$$ done using regular expressions.  Anyway, I'm fairly new to Perl, and I've
$$ come up with this approach for matching nested parentheses.  But it *feels*
$$ ugly, so . . .
$$ 
$$ In the spirit of TMTOWTDI, would anyone care to comment on how to make this
$$ better, faster, more efficient, or generally more Perlish?  One-liner,
$$ anyone?  :)  Anyway, here 'tis:


foreach ($i = 0; $str =~ /([()])/g;) {
    die "Not balanced" if (($i += $1 eq '(' ? 1 : -1) < 0);
}
die "Not balanced" if $i;




Abigail
-- 
perl  -e '$_ = q *4a75737420616e6f74686572205065726c204861636b65720a*;
          for ($*=******;$**=******;$**=******) {$**=*******s*..*qq}
          print chr 0x$& and q
          qq}*excess********}'


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

Date: 2 Feb 1999 22:47:30 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Match Parens-More Perlish?
Message-Id: <797va2$qgp$3@client2.news.psi.net>

Rob Partington (news@browser.org) wrote on MCMLXXXI September MCMXCIII in
<URL:news:slrn7beb9p.ams.news@riffraff.plig.net>:
|| 
|| If you're just testing whether they match, what about...
|| 
||  #! /usr/bin/perl -w
|| 
||  my $text=join('',<>);
||  1 while $text=~s/^(.*)\((.*)\)(.*)$/$1$2$3/; 
||  print $text=~m/\(|\)/,"\n";


That's quadratic in the length of the string.



Abigail
-- 
%0=map{reverse+chop,$_}ABC,ACB,BAC,BCA,CAB,CBA;$_=shift().AC;1while+s/(\d+)((.)
(.))/($0=$1-1)?"$0$3$0{$2}1$2$0$0{$2}$4":"$3 => $4\n"/xeg;print#Towers of Hanoi


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

Date: Tue, 02 Feb 1999 23:05:13 +0100
From: Frank de Bot <debot@xs4all.nl>
Subject: Numeric Value
Message-Id: <36B77698.D49B2FCC@xs4all.nl>

Does anybody knows a way to check if a string is numeric or not?


--
Hi, this piece is put automaticly under every mail from me.

Contact me: debot@xs4all.nl
Visit my page:  http://www.debot.nl/
    http://www.geocities.com/SunsetStrip/Frontrow/4346/top50index.html

I've much more homepage. You can just ask for them if you want.

Well, more I havn't to say, so have a nice day :-)




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

Date: Tue, 02 Feb 1999 22:31:56 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Numeric Value
Message-Id: <w1Lt2.37$9v3.3501@nsw.nnrp.telstra.net>

In article <36B77698.D49B2FCC@xs4all.nl>,
	Frank de Bot <debot@xs4all.nl> writes:
> Does anybody knows a way to check if a string is numeric or not?

Anybody who reads the perl faq knows this.

# perldoc perlfaq4
     How do I determine whether a scalar is a
     number/whole/integer/float?

> Hi, this piece is put automaticly under every mail from me.

And again, it's too long. Please shorten it.

Martien
-- 
Martien Verbruggen                  | 
Interactive Media Division          | 
Commercial Dynamics Pty. Ltd.       | Curiouser and curiouser, said Alice.
NSW, Australia                      | 


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

Date: Tue, 02 Feb 1999 22:23:56 GMT
From: birgitt@my-dejanews.com
Subject: Re: Perl Criticism [summary]
Message-Id: <797tth$uhl$1@nnrp1.dejanews.com>

In article <qeb297.217.ln@magna.metronet.com>,
  tadmc@metronet.com (Tad McClellan) wrote:
> topmind@technologist.com wrote:
> : In article <36B2780D.7D298414@mediaone.net>,
> :   "Michael D. Schleif" <mds-resource@mediaone.net> wrote:
> : >
> : > topmind@technologist.com wrote:
> : > >
> : > > So spelling and grammar are related to one's programming experiece.
> : >
> : > For once, I agree with topmind !!!
>
> : That was an indirect question, not a claim.
>
>    No it wasn't.
>
>    Questions end with a question mark.
>
>    Statements end with a period.

Please, can you tell me what a thread ends with ?
I will always use it properly if you tell me how to do it.

B.Funk

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Tue, 02 Feb 1999 22:19:33 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Perl syntax ( URGENT )
Message-Id: <VRKt2.35$9v3.3501@nsw.nnrp.telstra.net>

[Refer to other posts in this thread for pointers to documentation]

In article <36B70A1C.CC892B70@xs4all.nl>,
	Frank de Bot <debot@xs4all.nl> writes:
> Chop get the \n of a string. chop($var);

No. chop chops off the last character, regardless of what it is. You
are probably thinking of chomp, and that doesn't even do what you say
it does.

>> $line=$_;
>> $line =~ s/\s+/ /g;            ------------------->?
> 
> This makes a lot a spaces just one. If you have this text: Hello
> Everybody . It would be: Hello Everybody.

Not just spaces. Any whitespace. It replaces any occurrence of one or
more whitespace characters with a space. This also means that a
newline or a tab will be translated to a space.

The string "Hello\nEverybody .", which you mention above, will of
course become "Hello Everybody .". The regexp does not gobble up
whitespace before a full stop.

>>    @arr= split;                ------------------->?
> 
> Split makes from a string an array. This seems to do nothing. Use: @array =
> split(/ /, $string). Every word has it own place in the array

Read the documentation on split. If no expression is specified, it
splits $_. If no pattern is specified it will split on whitespace,
which is the same as a pattern of one space delimited by single quotes
(' ').

> Hi, this piece is put automaticly under every mail from me.

And it's too long. Please shorten it.

It is nice of you to want to help, but you should try to be a bit more
correct about the things you post.

Martien
-- 
Martien Verbruggen                  | My friend has a baby. I'm writing down
Interactive Media Division          | all the noises the baby makes so later
Commercial Dynamics Pty. Ltd.       | I can ask him what he meant - Steven
NSW, Australia                      | Wright


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

Date: 2 Feb 1999 22:49:08 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Perl syntax ( URGENT )
Message-Id: <797vd4$qgp$4@client2.news.psi.net>

kamez@my-dejanews.com (kamez@my-dejanews.com) wrote on MCMLXXX September
MCMXCIII in <URL:news:7955r3$if9$1@nnrp1.dejanews.com>:
[] 
[] could anyone explain me in detail the meaning of the following lines
[] in Perl ( i'm not familiar with ) , so it'll help to better  understand
[] to do other stuff :
[] 
[] chop                 ------------> what's the meaning of "chop" ?

RTFM



Abigail
-- 
perl -wleprint -eqq-@{[ -eqw+ -eJust -eanother -ePerl -eHacker -e+]}-


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

Date: 2 Feb 1999 22:52:48 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: read an html from a url
Message-Id: <797vk0$qgp$5@client2.news.psi.net>

Guillaume Buat-Menard (guillaume@nospam.com) wrote on MCMLXXXI September
MCMXCIII in <URL:news:7971am$rfc$1@newsreader2.core.theplanet.net>:
\\ Hi All,
\\ 
\\ I know there are some packages dedicated to the internet etc...
\\ The problem is that I don't want to download or install any package because
\\ I'm not gonna run the script on my test server but on another server that I
\\ don't know yet.

So, then what's the point of having a test server?

\\ I just need to find a routine or a compact package that will allow me to
\\ read an HTML (or text) page from a designated URL
\\ (http://theserver.com/myfile.html). I would like to run this package or
\\ routine on NT and UNIX with perl 5.


There's no answer to this question. First you say you don't want to
download a package, but yet, you want a package. Or perhaps you want
some to print out the libwww suite, mail it to you, and you type it
in, so you don't download it?



Abigail
-- 
perl -we '$@="\145\143\150\157\040\042\112\165\163\164\040\141\156\157\164".
             "\150\145\162\040\120\145\162\154\040\110\141\143\153\145\162".
             "\042\040\076\040\057\144\145\166\057\164\164\171";`$@`'


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

Date: Tue, 2 Feb 1999 13:32:25 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Regex for e-mail addresses?
Message-Id: <MPG.11210ec1badcb3669899f9@nntp.hpl.hp.com>

[Posted and a courtesy copy mailed.]

In article <797jou$64e$1@news1.Radix.Net> on 2 Feb 1999 19:30:38 GMT, Ed 
Hitler <revjack@radix.net> says...
 ... 
> Now I have a list that looks like this:
> 
> From: Mark Hamlin <mark.c.hamlin@bt.com>
> From: richm@ucesucks.rochester.rr.com (Rich)
> From: Douglas Nichols <dnichols@fhcrc.org>
> From: Kent Perrier <kperrier@blkbox.com>
> From: Mark Hamlin <mark.c.hamlin@bt.com>
> From: Kent Perrier <kperrier@blkbox.com>
> From: "sysadmin" <charlesjourdan@worldnet.att.net>
> From: droby@copyright.com
> From: Jessica Sockel <jsockel@drew.edu>
> From: Jerome O'Neil <jeromeo@atrieva.com>
> From: Kruman <#kruman#@radix.net>
> From: Richard Nilsson <qdtrini@jdicms88.ericsson.se>
> From: "DaveH" <DaveH@nnoossppaamm.acinom.com>
> 
> I am looking for a perl regex that will turn the above list into this:
> 
> mark.c.hamlin@bt.com
> richm@ucesucks.rochester.rr.com
> dnichols@fhcrc.org
> kperrier@blkbox.com
> mark.c.hamlin@bt.com
> kperrier@blkbox.com
> charlesjourdan@worldnet.att.net
> droby@copyright.com
> jsockel@drew.edu
> jeromeo@atrieva.com
> qdtrini@jdicms88.ericsson.se
> DaveH@nnoossppaamm.acinom.com
> 
> What I'm after is, "the stuff on either side of the @ sign, but not
> brackets or parentheses". 
> 
> The two regex lines I use work. I was just wondering if there was a more
> succinct or elegant way to do it. 

#!/usr/local/bin/perl -w
use strict;

while (<DATA>) {
	/^From:\s+(?:.*<)?([^>\s]+)/;
	print "$1\n";
}
__END__
From: Mark Hamlin <mark.c.hamlin@bt.com>
From: richm@ucesucks.rochester.rr.com (Rich)
From: Douglas Nichols <dnichols@fhcrc.org>
From: Kent Perrier <kperrier@blkbox.com>
From: Mark Hamlin <mark.c.hamlin@bt.com>
From: Kent Perrier <kperrier@blkbox.com>
From: "sysadmin" <charlesjourdan@worldnet.att.net>
From: droby@copyright.com
From: Jessica Sockel <jsockel@drew.edu>
From: Jerome O'Neil <jeromeo@atrieva.com>
From: Kruman <#kruman#@radix.net>
From: Richard Nilsson <qdtrini@jdicms88.ericsson.se>
From: "DaveH" <DaveH@nnoossppaamm.acinom.com>

A breakdown of the regex:

	/^From:    # Literal 'From:'
      \s+        # One or more white-space characters
      (?:.*<)?   # Anything up to a '<' if there is one
                 #   might also use (?:[^<]*<)? if get
                 #   up to the first '<' if more than one
      ([^>\s]+)  # Everything up to a '>' or white-space
                 #   or the end of the string
      /x;        # Phew!

This produces the desired result you give above, but also includes

  	#kruman#@radix.net

-- 
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: 2 Feb 1999 22:54:13 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Regex for e-mail addresses?
Message-Id: <797vml$qgp$6@client2.news.psi.net>

Ed Hitler (revjack@radix.net) wrote on MCMLXXXI September MCMXCIII in
<URL:news:7972n5$4ac$1@news1.Radix.Net>:
~~ Is there a single perl regular expression that will allow me to extract the
~~ e-mail addresses from the following header lines? 

/^From: (.*)/ && $email = $1;




Abigail
-- 
perl5.004 -wMMath::BigInt -e'$^V=new Math::BigInt+qq;$^F$^W783$[$%9889$^F47$|8;
 .qq;8768$^W596577669$%$^W5$^F3364$[$^W$^F$|838747$[8889739$%$|$^F673$%$^W98$^F;
 .qq;76777$=56;;$^U=substr($]=>$|=>5)*(q.25..($^W=@^V))=>do{print+chr$^V%$^U;$^V
/=$^U}while$^V!=$^W'


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

Date: Tue, 02 Feb 1999 22:03:30 +0100
From: Martin Baur <martin.baur@mindpower.com>
Subject: Sockets still don't work at my place
Message-Id: <36B76822.4F8B7665@mindpower.com>


--------------6111A8F1A5DA2A88994B7AA9
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hi

This code (kindly receved by Marquis) is used to send to a Java-built
Listener Process on NT which just listens to and prints the message
received to the screen. It notifies me about the connection being
successfully established, however, it does not seem to receive anything
and therefore does not return an answer string.

The Perl script therefore blocks and I have to terminate it. I tried
several variations .. to no avail ...

Can anybody point out why? Needless to say that its even more urgent
than yesterday ... :-(

---
use IO::Socket;

# $host = shift;
$host = "212.45.192.150";
# $port = shift;
$port = 5005;

$line =
"SBS/1/Create_Order?FORMAT=VERSION=1.0&&ID_USER=0&USER=NAME=Baur&&VORNAME=Martin&&L_ADRESSE1=Poststrasse
7&&L_ADRESSE2=&&L_ADRESSE3=&&L_PLZ=8805&&L_ORT=Richterswil&&R_ADRESSE1=Poststrasse
7&&R_ADRESSE2=&&R_ADRESSE3=&&R_PLZ=8805&&R_ORT=Richterswil&&TEL=&&FAX=&&E_MAIL&&KAT_ID=1&ORDERPOS1=ART_ID=10&&MENGE=5&ORDERPOS2=ART_ID=9&&MENGE=3";

$remote = IO::Socket::INET -> new (
          Proto => "tcp",
          PeerAddr => $host,
          PeerPort => $port) ||
     die "Could not open socket: $!\n";
  $remote->autoflush(1);
  print $remote "$line";
#  $remote->send ($line);
  $return = <$remote>;
  print "$return\n";
close($remote);
---

Yes, the line is exactly this ...

Please email or post your ideas quickly. Many thanks

Martin
--

MindPower
EDV-Dienste
__________________________________________________________
 Internet-Mail:    martin.baur@mindpower.com.xyz
 Internet (biz):   http://www.mindpower.com
 Internet (priv):  http://www.mindpower.com/mb-es (german)
 PGP-Key:          http://www.mindpower.com/pgp.htm
 Voice:            +41-1-687 11 66
__________________________________________________________
 Visit and join our Web-based BBS! If you're pleased, why
 not run your own? We're happy to get into contact! Try:
 http://www.mindpower.com/scripts/dbh.isa/EnterBBS?d=6931
__________________________________________________________
 To prevent SPAM: When mailing to us, remove xyz first!


--------------6111A8F1A5DA2A88994B7AA9
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
Hi
<p>This code (kindly receved by Marquis) is used to send to a Java-built
Listener Process on NT which just listens to and prints the message received
to the screen. It notifies me about the connection being successfully established,
however, it does not seem to receive anything and therefore does not return
an answer string.
<p>The Perl script therefore blocks and I have to terminate it. I tried
several variations .. to no avail ...
<p>Can anybody point out why? Needless to say that its even more urgent
than yesterday ... :-(
<p><tt>---</tt>
<br><tt>use IO::Socket;</tt><tt></tt>
<p><tt># $host = shift;</tt>
<br><tt>$host = "212.45.192.150";</tt>
<br><tt># $port = shift;</tt>
<br><tt>$port = 5005;</tt><tt></tt>
<p><tt>$line = "SBS/1/Create_Order?FORMAT=VERSION=1.0&amp;&amp;ID_USER=0&amp;USER=NAME=Baur&amp;&amp;VORNAME=Martin&amp;&amp;L_ADRESSE1=Poststrasse
7&amp;&amp;L_ADRESSE2=&amp;&amp;L_ADRESSE3=&amp;&amp;L_PLZ=8805&amp;&amp;L_ORT=Richterswil&amp;&amp;R_ADRESSE1=Poststrasse
7&amp;&amp;R_ADRESSE2=&amp;&amp;R_ADRESSE3=&amp;&amp;R_PLZ=8805&amp;&amp;R_ORT=Richterswil&amp;&amp;TEL=&amp;&amp;FAX=&amp;&amp;E_MAIL&amp;&amp;KAT_ID=1&amp;ORDERPOS1=ART_ID=10&amp;&amp;MENGE=5&amp;ORDERPOS2=ART_ID=9&amp;&amp;MENGE=3";</tt><tt></tt>
<p><tt>$remote = IO::Socket::INET -> new (</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Proto =>
"tcp",</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PeerAddr
=> $host,</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PeerPort
=> $port) ||</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp; die "Could not open socket: $!\n";</tt>
<br><tt>&nbsp; $remote->autoflush(1);</tt>
<br><tt>&nbsp; print $remote "$line";</tt>
<br><tt>#&nbsp; $remote->send ($line);</tt>
<br><tt>&nbsp; $return = &lt;$remote>;</tt>
<br><tt>&nbsp; print "$return\n";</tt>
<br><tt>close($remote);</tt>
<br><tt>---</tt>
<p>Yes, the line is exactly this ...
<p>Please email or post your ideas quickly. Many thanks
<p>Martin
<br>--
<p>MindPower
<br>EDV-Dienste
<br>__________________________________________________________
<br>&nbsp;Internet-Mail:&nbsp;&nbsp;&nbsp; martin.baur@mindpower.com.xyz
<br>&nbsp;Internet (biz):&nbsp;&nbsp; <A HREF="http://www.mindpower.com">http://www.mindpower.com</A>
<br>&nbsp;Internet (priv):&nbsp; <A HREF="http://www.mindpower.com/mb-es">http://www.mindpower.com/mb-es</A> (german)
<br>&nbsp;PGP-Key:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<A HREF="http://www.mindpower.com/pgp.htm">http://www.mindpower.com/pgp.htm</A>
<br>&nbsp;Voice:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+41-1-687 11 66
<br>__________________________________________________________
<br>&nbsp;Visit and join our Web-based BBS! If you're pleased, why
<br>&nbsp;not run your own? We're happy to get into contact! Try:
<br>&nbsp;<A HREF="http://www.mindpower.com/scripts/dbh.isa/EnterBBS?d=6931">http://www.mindpower.com/scripts/dbh.isa/EnterBBS?d=6931</A>
<br>__________________________________________________________
<br>&nbsp;To prevent SPAM: When mailing to us, remove xyz first!
<br>&nbsp;</html>

--------------6111A8F1A5DA2A88994B7AA9--



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

Date: 2 Feb 1999 22:56:45 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Statistics for comp.lang.perl.misc
Message-Id: <797vrd$qgp$7@client2.news.psi.net>

Bart Lateur (bart.lateur@skynet.be) wrote on MCMLXXXI September MCMXCIII
in <URL:news:36b70dc3.326584@news.skynet.be>:
() Greg Bacon wrote:
() 
() >OCR      orig /  body  Posts  Address
() 
() >0.964  ( 32.9 / 34.1)     54  abigail@fnx.com
() 
() No way that Abigail has a 96.4% OCR. 20% would be more like it.


Perhaps you should produce your own statistics.



Abigail
-- 
%0=map{reverse+chop,$_}ABC,ACB,BAC,BCA,CAB,CBA;$_=shift().AC;1while+s/(\d+)((.)
(.))/($0=$1-1)?"$0$3$0{$2}1$2$0$0{$2}$4":"$3 => $4\n"/xeg;print#Towers of Hanoi


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

Date: Tue, 02 Feb 1999 22:24:16 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: substituting keywords in a string
Message-Id: <kWKt2.36$9v3.3501@nsw.nnrp.telstra.net>

In article <36be8c27.22252060@news.cyberway.com.sg>,
	pigs_can_fly@mindless.com (Jason Q.) writes:
> mgjv@comdyn.com.au (Martien Verbruggen) wrote:
> 
>>Use \b in your regexp
> 
> Like that?
> 
> $string =~ s/\b($_)\b/<font color=darkred>$1<\/font>/gi;

Yep.

> if keywords included "font", "color" or "darkred", my problem would
> still be there, wouldn't it?

Yep. If your string contains HTML, and your replacement stuff contains
HTML keywords then you have a serious problem. The only way to do it
correctly, that I can think of, is to use HTML::Parser or its ilk to
parse the HTML, and only do substitutions on the text parts.

If you _start_ with a string without HTML, then all you need to do is
do all the substitutions in one go, as ex0plained in another answer to
your question.

HTH,
Martien
-- 
Martien Verbruggen                  | 
Interactive Media Division          | Begin at the beginning and go on till
Commercial Dynamics Pty. Ltd.       | you come to the end; then stop.
NSW, Australia                      | 


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

Date: 02 Feb 1999 16:01:18 -0500
From: Uri Guttman <uri@ibnets.com>
Subject: Re: UNIX 'tail' command in Perl??
Message-Id: <397lu0frkx.fsf@ibnets.com>

>>>>> "PS" == Peter Smith <psmith01@mindspring.com> writes:


  PS> sorry, I wasn't too clear on that.  actually, I wanted to read
  PS> backwards and chop, or some combo in between.  I'm just looking
  PS> for the most efficient way to get the file into a usable format
  PS> for my biz folks.  I'll check out tom c.'s recipe also...I also
  PS> have a program called Data Junction which may also help...

don't use my module if you are going to chop. it is not meant for that
and i have no idea how it will behave in that situation. it is purely
for reading files backwards by lines.

uri

-- 
Uri Guttman                             Hacking Perl for Ironbridge Networks
uri@sysarch.com				uri@ironbridgenetworks.com	


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

Date: Tue, 02 Feb 1999 21:57:48 GMT
From: mcafee@waits.facilities.med.umich.edu (Sean McAfee)
Subject: Re: UNIX 'tail' command in Perl??
Message-Id: <wxKt2.5294$Ge3.21700951@news.itd.umich.edu>

In article <36B75FB3.9594626@mindspring.com>,
Peter Smith  <psmith01@mindspring.com> wrote:
>I have a 650MB text file with 162,000 recortds that I need to do
>something with - I haven't yet been able to open with Access/Excel/etc. 
>Soooooo, I thought I might be able to chop it up using the tail
>command.  I don't have access to a UNIX box, however.

>So I need an efficient tail command so I can chop off the last x
>thousand records.  How do I use Perl to get the last 10 records?

It's not clear what your record separator is, but assuming it's a newline,
this is about the shortest I could manage:

$block = 100;  # tune this to roughly your record length
$lines = 10;   # number of lines from end of file you want

open(FILE, "myfile") ? seek(FILE, -$block, 2) : die "Can't open: $!\n";
do {
	read(FILE, substr($buf,0,0), $block);
	seek(FILE, -2*$block, 1);
} while ($n = ($buf =~ tr/\012// - $lines)) <= 0;
$buf =~ s|(?:.*?\n){$n}||;
# $buf now contains the last $lines lines in the file

You might need to change that \012 to be same as \n if it's different on
your system, and may need to add a "binmode FILE;" before the do loop.  The
algorithm will break if it tries to read past the beginning of the file,
but if it's as huge as you say it shouldn't be a problem.

Making the algorithm more robust is left as an exercise for the reader.

-- 
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: Tue, 02 Feb 1999 16:30:58 -0500
From: fl_aggie@thepentagon.com (I R A Aggie)
Subject: Re: Visual Perl?
Message-Id: <fl_aggie-0202991630580001@aggie.coaps.fsu.edu>

In article <36b755e5.577316@news.skynet.be>, bart.lateur@skynet.be (Bart
Lateur) wrote:

+ Martien Verbruggen wrote:
+ 
+ >> Yeah, this reminds me of a popular program called GirlFriend 1.0. It
+ >> doesn't always know what you want either.  But then again, I don't think
+ >> it is a Perl Script.
+ >
+ >I upgraded mine to Wife 1.0. Works a lot better :)
+ 
+ The problem is that the Wife module and the GirlFriend module don't work
+ too well together.

That's because the both have:

use Available::Resources; # which causes many conflicts.

James


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

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 4809
**************************************

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