[23980] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6181 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Feb 23 03:05:37 2004

Date: Mon, 23 Feb 2004 00:05:08 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Mon, 23 Feb 2004     Volume: 10 Number: 6181

Today's topics:
    Re: Beginner question on @INC <alex.zeng@digi-go.com>
    Re: finding common words <dwall@fastmail.fm>
    Re: finding common words <dwall@fastmail.fm>
    Re: help on hash of hashes (Stephen Moon)
        Help with Dynamic load pm. <pengtaoli@hotmail.com>
    Re: how to get a http request header in perl? <alex.zeng@digi-go.com>
    Re: html2text but preserving text links (Felix)
        IN PLACE edit syntax help needed <randy@SpamFree.com>
    Re: IN PLACE edit syntax help needed (Sam Holden)
    Re: Listbox and passing entries <Joe.Smith@inwap.com>
        Perl complex data structure ... how to get more flexibl (valued customer)
    Re: Posting Usenet News Messages <Joe.Smith@inwap.com>
    Re: Private methods within a Perl Object module (Jay Tilton)
    Re: Private methods within a Perl Object module <uri@stemsystems.com>
    Re: Private methods within a Perl Object module <uri@stemsystems.com>
        removeing first 3 columns from the lines in file (ajay)
    Re: removeing first 3 columns from the lines in file (Sam Holden)
    Re: removeing first 3 columns from the lines in file <myhandle@lucent.com>
    Re: Simple code runs on linux, but not on windows -- wh <tassilo.parseval@rwth-aachen.de>
    Re: trapping file i/o error <uri@stemsystems.com>
    Re: trapping file i/o error <tassilo.parseval@rwth-aachen.de>
        use Net::protoent no longer works w/ FreeBSD perl 5.6.1 (Paul Southworth)
    Re: use Net::protoent no longer works w/ FreeBSD perl 5 <usenet@morrow.me.uk>
    Re: use Net::protoent no longer works w/ FreeBSD perl 5 (Paul Southworth)
    Re: use Net::protoent no longer works w/ FreeBSD perl 5 (Sam Holden)
    Re: Why is Perl losing ground? <beable+unsenet@beable.com.invalid>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 23 Feb 2004 01:31:06 -0600
From: Alex Zeng <alex.zeng@digi-go.com>
Subject: Re: Beginner question on @INC
Message-Id: <4039AC3A.4030507@digi-go.com>


> Anyway, I have found that if I remove 5.8.0 completely and then install
> 5.8.1 it works.  (I can't install 5.8.3 till I get to a system that is
> faster than my 26k dialup).  If I install 5.8.1 over the top of 5.8.0 I
> get the @INC problem.  So, I can fix the problem - I just don't quite
> understand it yet.
> 
> Thank you
> Geedunk
> 

I am reading perltk.com site, and here is an sample

http://www.perltk.org/articles/pm1.htm
-------
  1 #!/usr/local/bin/perl -w
  2 #
  3 # frog, Sun Apr 11 18:01:41 1999
  4
  5 use 5.005;
  6 use Tk 8.0;
  7 use Tk::widgets qw/Dialog/;
  8 use subs qw/build_menubar fini init/;
  9 use vars qw/$MW $VERSION/;
10 use strict;
11
12 $MW = MainWindow->new;
13 init;
14 MainLoop;
 ...
--------

It appears the perl tk sample codes use the line "use 5.005" often, 
which I think it is set during the PerlTK installation process. Look 
into the Makefile.PL if that is how your install your TK module.

         gunzip Tk800.013.tar.gz
         tar -xvf Tk800.013.tar
         cd Tk800.013
         perl Makefile.PL
         make
         make test
         make install

@INC variable is used everytime you use the statement like "use..." 
"requires ..." it is just a pointer poiting to the location of the library,

http://www.perldoc.com/perl5.8.0/pod/perlvar.html
------------
     The array @INC contains the list of places that the do EXPR, 
require, or use constructs look for their library files. It initially 
consists of the arguments to any -I command-line switches, followed by 
the default Perl library, probably /usr/local/lib/perl, followed by ".", 
to represent the current directory. ("." will not be appended if taint 
checks are enabled, either by -T or by -t.) If you need to modify this 
at runtime, you should use the use lib pragma to get the 
machine-dependent library properly loaded also:

     use lib '/mypath/libdir/';
     use SomeMod;

     You can also insert hooks into the file inclusion system by putting 
Perl code directly into @INC. Those hooks may be subroutine references, 
array references or blessed objects. See perlfunc/require for details.
------------

I would doubt it would slow your program down in any way



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

Date: Mon, 23 Feb 2004 03:42:35 -0000
From: "David K. Wall" <dwall@fastmail.fm>
Subject: Re: finding common words
Message-Id: <Xns9497E7045F8A0dkwwashere@216.168.3.30>

Gunnar Hjalmarsson <noreply@gunnar.cc> wrote:

> David K. Wall wrote:
>> viv2k@hotmail.com (viv2k) wrote:
>>> Right now, I have two very long lists of words with comments
>>> attached to each of the words and I want to find the words that
>>> are common in both of them.
>> 
>> perldoc -q intersection
>> 
>> Gunnar Hjalmarsson has already posted working code. I just wanted
>> to point to the FAQ entry, as the code there is readily adapted to
>> the above problem.
> 
> Well, applying that FAQ entry, you could do something like this:
> 
>      my ($elem, %count, %intersection);
>      for $elem (keys %ListA, keys %ListB) { $count{$elem}++ }
>      for $elem (keys %count) {
>          $intersection{$elem} = "$ListA{$elem} : $ListB{$elem}"
>            if $count{$elem} > 1;
>      }
>      print "$_\t$intersection{$_}\n" for sort keys %intersection;
> 
> But provided that it makes sense to start with populating two hashes
> with the lists of words + comments, I don't really see that the FAQ
> entry is very well adapted, since applying it would not take advantage
> of the initial hashes.

How about this?

    my %ListA = ( apple => 1.1, banana => 2.2, cat => 3.3 );
    my %ListB = ( apple => 100, boy => 500, cat => 1000 );
    my %count;
    my (%count, @intersection);    
    for my $element (keys %ListA, keys %ListB) { 
        push @intersection, $element if ++$count{$element} > 1;
    }
    my (%new_ListA, %new_ListB);
    @new_ListA{@intersection} = @ListA{@intersection};
    @new_ListB{@intersection} = @ListB{@intersection};

It's a bit different from the FAQ, but was directly inspired by it... 
<shrug>

If memory is a consideration I'd go with deleting the non-intersecting 
elements. Neat idea, and one that didn't occur to me.

-- 
David Wall


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

Date: Mon, 23 Feb 2004 05:54:48 -0000
From: "David K. Wall" <dwall@fastmail.fm>
Subject: Re: finding common words
Message-Id: <Xns949894BBAF90dkwwashere@216.168.3.30>

"David K. Wall" <dwall@fastmail.fm> wrote:

>     my %ListA = ( apple => 1.1, banana => 2.2, cat => 3.3 );
>     my %ListB = ( apple => 100, boy => 500, cat => 1000 );
>     my %count;
>     my (%count, @intersection);    

Oops, extra declaration. I originally wrote it as a for() loop followed by a 
grep(), but then saw that the grep() could be eliminated and just re-pasted 
the part I changed.

>     for my $element (keys %ListA, keys %ListB) { 
>         push @intersection, $element if ++$count{$element} > 1;
>     }
>     my (%new_ListA, %new_ListB);
>     @new_ListA{@intersection} = @ListA{@intersection};
>     @new_ListB{@intersection} = @ListB{@intersection};


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

Date: 22 Feb 2004 23:59:49 -0800
From: vibfft@yahoo.com (Stephen Moon)
Subject: Re: help on hash of hashes
Message-Id: <9feadd98.0402222359.2cb4900@posting.google.com>

Anno,

> > --------------------------------------------------------
> > #!/usr/bin/perl
> > use strict; use warnings;
> > 
> > my @columns = transpose( map [ split], <DATA>);
> > 
> > print "@$_\n" for shift @columns; # print header
> > foreach ( @columns ) {
> >      print join( ', ', @$_), "\n"; # print role columns
> > }
> > 
> > sub transpose {
> >     my $max = 0;
> >     $max > @$_ or $max = @$_ for @_; # length of longest line
> >     map [ map shift( @$_) || '', @_], 1 .. $max;
> > }

I have a hard time figuring out how transpose function.  Maybe, a
little explanation?  Especially where you have "map [ map shift( @$_)
|| '',@_], 1 .. $max"  Furthermore, what would be difference in using
{} instead of [].

-Steve
> > 
> > __DATA__
> > flintstones: lead=fred pal=barney 
> > jetsons: lead=george wife=jane boy=elroy
> > simpsons: lead=homer wife=marge kid=bart
> 
> cool!  I will check it out!  Well, the reason that I use sort is
> because I will have frequency index associated with magnitudes.
> 
> Thanks for your help.
> 
> -Steve


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

Date: Mon, 23 Feb 2004 15:55:01 +0800
From: "Franklin Lee" <pengtaoli@hotmail.com>
Subject: Help with Dynamic load pm.
Message-Id: <c1cbl8$m9b@netnews.proxy.lucent.com>

Hi all,

I met below problem.

When first run my program, I will load my own lib, such as
/opt/myapp/lib1/mylib.pm.
code:
push(@INC, "/opt/myapp/lib1");
require mylib;
 .....

In the middle of my program, I will create new lib, such as
/var/tmp/myapp/lib/mylib.pm.
This file is new lib file I should use and contain same functions as
/opt/myapp/lib1/mylib.pm
Now I want to use the functions in /var/tmp/myapp/lib/mylib.pm instead of
/opt/myapp/lib1/mylib.pm
Then how should I do?

Thank you!

Franklin




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

Date: Mon, 23 Feb 2004 00:18:12 -0600
From: Alex Zeng <alex.zeng@digi-go.com>
Subject: Re: how to get a http request header in perl?
Message-Id: <40399B24.6000302@digi-go.com>

That is for HTTP server. For HTTP client, which is what I think you are 
asking, you shall used libwww, a perl suite that simulate a web browser.
Do a search on libwwww


prabs wrote:

>  i want to get a http request header using perl.Can i use http::daemon for that? 
> 
> 



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

Date: 22 Feb 2004 18:45:08 -0800
From: google_answers@festmail.com (Felix)
Subject: Re: html2text but preserving text links
Message-Id: <62dd5c5b.0402221845.5394d732@posting.google.com>

I figured out a way to do this. Basically by using the existing code
and converting div tags into <br> tags first.

Thanks for getting back to me.

Marc.


> What command line options are you using with lynx?  That may help.
> 
> -- 
> Jim
> 
> Copyright notice: all code written by the author in this post is
>  released under the GPL. http://www.gnu.org/licenses/gpl.txt 
> for more information.
> 
> a fortune quote ...
> World War Three can be averted by adherence to a strictly
> enforced dress code!


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

Date: Mon, 23 Feb 2004 04:32:00 GMT
From: "Randy Harris" <randy@SpamFree.com>
Subject: IN PLACE edit syntax help needed
Message-Id: <4nf_b.4801$t16.3539989@newssvr28.news.prodigy.com>

I've tried every syntax combination that I can think of.  Would someone
kindly tell me the correct syntax.

E:\Documents>perl -i -p -e s/(var showPartFileIcon)=true/$1=false/i rrh.html
Substitution pattern not terminated at -e line 1.

E:\Documents>perl -i -p -e 's/(var showPartFileIcon)=true/$1=false/i
rrh.html'
Can't find string terminator "'" anywhere before EOF at -e line 1.

E:\Documents>perl -i -p -e 's/(var showPartFileIcon)=true/$1=false/i'
rrh.html
Can't find string terminator "'" anywhere before EOF at -e line 1.

E:\Documents>perl -i -p -e 's/(var showPartFileIcon)=true/$1\=false/i'
'rrh.html'
Can't find string terminator "'" anywhere before EOF at -e line 1.

E:\Documents>perl -i -p -e 's/(var showPartFileIcon)\=true/$1\=false/i'
'rrh.html'
Can't find string terminator "'" anywhere before EOF at -e line 1.

E:\Documents>perl -i -p -e 's/(var showPartFileIcon)\=true/$1\=false/i;'
'rrh.html'
Can't find string terminator "'" anywhere before EOF at -e line 1.

E:\Documents>perl -i -p -e 's/(var showPartFileIcon)\=true/$1\=false/i'
'rrh.html;'
Can't find string terminator "'" anywhere before EOF at -e line 1.

Thanks in advance




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

Date: 23 Feb 2004 05:23:02 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: IN PLACE edit syntax help needed
Message-Id: <slrnc3j3hm.f1e.sholden@flexal.cs.usyd.edu.au>

On Mon, 23 Feb 2004 04:32:00 GMT, Randy Harris <randy@SpamFree.com> wrote:
> I've tried every syntax combination that I can think of.  Would someone
> kindly tell me the correct syntax.
> 
> E:\Documents>perl -i -p -e s/(var showPartFileIcon)=true/$1=false/i rrh.html
> Substitution pattern not terminated at -e line 1.

perl -i -p -e "s/(var showPartFileIcon)=true/$1=false/i" rrh.html

I'm assuming that's a place holder argument of some sort, not much
point capturing a constant string (though I guess it saves some typing
and possible typos)...

[snip examples using ']

The dos/windows command shell uses double quotes not single quotes for
argument quoting. Under unix the above won't work since the $1 will be
interpreted as a shell variable.

Surely your Operating System came with some sort of documention?

-- 
Sam Holden


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

Date: Mon, 23 Feb 2004 02:51:43 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: Listbox and passing entries
Message-Id: <3Vd_b.41743$4o.58497@attbi_s52>

Gunnar Hjalmarsson wrote:

> Since the SplitParam() function is available, OP is apparently using a
> version of cgi-lib.pl that handles multiple values. Bearing that in
> mind, which "known bug" are you referring to, Joe?

Never mind, I missed that part.

But the question for Old School remains: why not upload a different
CGI-parsing library.

	-Joe


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

Date: 22 Feb 2004 23:31:33 -0800
From: scooterm@hotmail.com (valued customer)
Subject: Perl complex data structure ... how to get more flexible access? how to avoid eval?
Message-Id: <1b347673.0402222331.6c6c55ec@posting.google.com>

### QUESTION
You have a complex perl data structure that you want to access using a
flexible 'xpath-like' syntax supplied in a simple string. How can this
be done elegantly??

### EXAMPLE
Suppose you have a perl data structure that looks something like this
 ...

$news  = {};
$news->{top_stories} = ##* ... code-omitted ...*;
$news->{sports}      = ##* ... code-omitted ...*;
$news->{weather}     = ##* ... code-omitted ...*

You can infer what the omitted parts look like from the following
sample data nodes ...

### get stuff about todays top story
    print   $news->{top_stories}[0]{headline};  
    print   $news->{top_stories}[0]{bodytext};  

### get stuff about the weather
    print   $news->{weather}{forecast}[3]{temp}; ## forecast day 3
    print   $news->{weather}{current}{temp}; 

### PROBLEM DETAILS
How do you allow a user to arbitrarily access any single data node of
any arbitrary depth in the data structure, simply by specifying a
single query string?

eg; 'news/top_stories/[0]/headline'
eg; 'news/weather/current/temp'
eg; 'news/weather/forecast/[2]/temp'
eg; 'news/classifieds/for_sale/vehicles/trucks/[12]/asking_price'

Is there a more elegant solution than splitting the string,
concatenating
and then doing 'eval'? Dereferencing with '${}' does not seem flexible
enough because
the application does not know in advance how many 'path steps' the
user will
supply in the query string. Is there an XPath-like syntax module
available, or an alternative approach?


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

Date: Mon, 23 Feb 2004 02:47:18 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: Posting Usenet News Messages
Message-Id: <VQd_b.105766$uV3.588177@attbi_s51>

Camelback Jones wrote:

> Actually, as it turns out, Tad - whatever his knowledge may or may not be - 
> is wrong about that. Now that I finally have it working, it doesn't matter 
> whether there's a space there or not, which is exactly what I thought in 
> the first place.

While it may be true that is does not matter with the module you are
using, it does make a difference to the NNTP server.  If you watch
the bytes leaving your socket, you'll see that the NNTP server
will _not_ accept "\n \n" for the mandatory blank line separating
the body from the headers.
	-Joe


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

Date: Mon, 23 Feb 2004 03:22:01 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Private methods within a Perl Object module
Message-Id: <40396c93.472410475@news.erols.com>

Ben Morrow <usenet@morrow.me.uk> wrote:

: 
: Uri Guttman <uri@stemsystems.com> wrote:
: > he wasn't that far off but i agree with your general sentiment. first, i
: > would never do this as it gains little. why shouldn't code that uses
: > this module be able to call those methods and instead be forced to call
: > them through this table. there is no noticeable benefit that i can see.
: 
: The OP's stated intent was that these methods should be private: i.e.
: not callable from outside the class...

Actually, he said "module," not "class," which suggested to me that he
wants the method accessible only within the file's lexical scope.  This
deserves some clarification from the OP.

: to make this work, I would ditch
: the action() method and instead use AUTOLOAD:
: 
: use Carp;
: 
: our $AUTOLOAD;
: 
: sub AUTOLOAD {
:     (my $meth = $AUTOLOAD) =~ s/.*:://;
:     __PACKAGE__ eq caller and exists $dispatch{$meth}
:         or croak "Undefined subroutine &$AUTOLOAD called";
:     goto &$dispatch{$meth};

Should be:

      goto &{ $dispatch{$meth} };

: }

If he does want the method to be private to a lexical scope, that technique
is easily subverted by changing into the right package, e.g.

    my $obj = MyClass->new;
    {
        package MyClass;
        $obj->some_private_method;
    }



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

Date: Mon, 23 Feb 2004 04:06:29 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Private methods within a Perl Object module
Message-Id: <x7ptc6fni3.fsf@mail.sysarch.com>

>>>>> "BM" == Ben Morrow <usenet@morrow.me.uk> writes:

  BM> Uri Guttman <uri@stemsystems.com> wrote:
  >> he wasn't that far off but i agree with your general sentiment. first, i
  >> would never do this as it gains little. why shouldn't code that uses
  >> this module be able to call those methods and instead be forced to call
  >> them through this table. there is no noticeable benefit that i can see.

  BM> The OP's stated intent was that these methods should be private: i.e.
  BM> not callable from outside the class... to make this work, I would ditch
  BM> the action() method and instead use AUTOLOAD:

  BM> use Carp;

  BM> our $AUTOLOAD;

  BM> sub AUTOLOAD {
  BM>     (my $meth = $AUTOLOAD) =~ s/.*:://;
  BM>     __PACKAGE__ eq caller and exists $dispatch{$meth}
  BM>         or croak "Undefined subroutine &$AUTOLOAD called";
  BM>     goto &$dispatch{$meth};
  BM> }

that would work and be slower. my example of how to properly initialize
the dispatch table would work too and be faster. and i left the one bug
as an exercise to the OP. now there can a need for private methods and
perl6 will support them. i just want to hear the OP justify why it is
necessary in this case.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Mon, 23 Feb 2004 04:17:14 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Private methods within a Perl Object module
Message-Id: <x7fzd2fn06.fsf@mail.sysarch.com>

>>>>> "JT" == Jay Tilton <tiltonj@erols.com> writes:

  JT> Ben Morrow <usenet@morrow.me.uk> wrote:

  JT> : our $AUTOLOAD;
  JT> : 
  JT> : sub AUTOLOAD {
  JT> :     (my $meth = $AUTOLOAD) =~ s/.*:://;
  JT> :     __PACKAGE__ eq caller and exists $dispatch{$meth}
  JT> :         or croak "Undefined subroutine &$AUTOLOAD called";
  JT> :     goto &$dispatch{$meth};

  JT> Should be:

  JT>       goto &{ $dispatch{$meth} };

  JT> : }

  JT> If he does want the method to be private to a lexical scope, that
  JT> technique is easily subverted by changing into the right package,
  JT> e.g.

  JT>     my $obj = MyClass->new;
  JT>     {
  JT>         package MyClass;
  JT>         $obj->some_private_method;
  JT>     }

good catch. i would just use a lexical dispatch table that was assigned
sub refs directly. no muss, no fuss. but the OP is silent. i will wait
to hear back from him.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: 22 Feb 2004 20:45:17 -0800
From: ajay_kumarsingh@yahoo.com (ajay)
Subject: removeing first 3 columns from the lines in file
Message-Id: <2a0aec36.0402222045.6bbee2fd@posting.google.com>

In log file i have lines like this:

01-22T09:26:24.560 [00504] (tShell)     {0xd071920}
Alcap_menu::send_establish_response] | SUCCESS

It's single line. now i want to remove first 3 columns( better to say
first 3 set of strings seperated by spaces) of line and retain rest of
line, i.e I want to have only this:

Alcap_menu::send_establish_response] | SUCCESS

How to do it in a single perl command ?

Tx


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

Date: 23 Feb 2004 05:28:57 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: removeing first 3 columns from the lines in file
Message-Id: <slrnc3j3sp.f1e.sholden@flexal.cs.usyd.edu.au>

On 22 Feb 2004 20:45:17 -0800, ajay <ajay_kumarsingh@yahoo.com> wrote:
> In log file i have lines like this:
> 
> 01-22T09:26:24.560 [00504] (tShell)     {0xd071920}
> Alcap_menu::send_establish_response] | SUCCESS
> 
> It's single line. now i want to remove first 3 columns( better to say
> first 3 set of strings seperated by spaces) of line and retain rest of
> line, i.e I want to have only this:
> 
> Alcap_menu::send_establish_response] | SUCCESS
> 
> How to do it in a single perl command ?

Does preserving exact whitespace matter?

perl -lane 'print "@F[3..$#F]"' 

If it does:

perl -pe "s/^\S+\s+\S+\s+\S+//"

Or the now leading space should also go:

perl -pe "s/^\S+\s+\S+\s+\S+\s+//"

replace \s+ with ' ' or \t or whatever if the whitespace is more
restrictively defined (which would allow \S* to be useful for empty
fields...)

-- 
Sam Holden


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

Date: Mon, 23 Feb 2004 11:26:55 +0530
From: ajay <myhandle@lucent.com>
Subject: Re: removeing first 3 columns from the lines in file
Message-Id: <40399627.F8D88A2B@lucent.com>

Tx Sam it works
This is the command which solves my purpose.

perl -pi -e "s/^\S+\s+\S+\s+\S+\s+\S+\s+//" log_file


Sam Holden wrote:
> 
> On 22 Feb 2004 20:45:17 -0800, ajay <ajay_kumarsingh@yahoo.com> wrote:
> > In log file i have lines like this:
> >
> > 01-22T09:26:24.560 [00504] (tShell)     {0xd071920}
> > Alcap_menu::send_establish_response] | SUCCESS
> >
> > It's single line. now i want to remove first 3 columns( better to say
> > first 3 set of strings seperated by spaces) of line and retain rest of
> > line, i.e I want to have only this:
> >
> > Alcap_menu::send_establish_response] | SUCCESS
> >
> > How to do it in a single perl command ?
> 
> Does preserving exact whitespace matter?
> 
> perl -lane 'print "@F[3..$#F]"'
> 
> If it does:
> 
> perl -pe "s/^\S+\s+\S+\s+\S+//"
> 
> Or the now leading space should also go:
> 
> perl -pe "s/^\S+\s+\S+\s+\S+\s+//"
> 
> replace \s+ with ' ' or \t or whatever if the whitespace is more
> restrictively defined (which would allow \S* to be useful for empty
> fields...)
> 
> --
> Sam Holden


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

Date: 23 Feb 2004 07:04:10 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: Simple code runs on linux, but not on windows -- why?
Message-Id: <c1c8la$4jn$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Tad McClellan:

> Lukas Mai <rwxr-xr-x@gmx.de> wrote:
>> Tad McClellan schrob:
>> [...]
>> 
>>> You should not use modifiers that you don't understand. m//o is
>>> useless for your pattern.
>> 
>>>    my $tail = $1 if $the_number =~ m/\d+(.*)/s;
>> 
>> Whoa! Don't do that! 
> 
> 
> Why not?

Because one day it will emit a warning.

>> The behaviour of
>> `my $foo if bar;' is undefined 
> 
> 
> I believe that that is incorrect.
> 
> The docs themselves use that form twice that I can see:
> 
>    perl -ne 'print "$ARGV: $_" if /^\s+my\b.*\bif\b/' *.pod
> 
>    perltooc.pod:   my $class = ref $self if $self;
>    perlwin32.pod:  my @g = File::DosGlob::glob($_) if /[*?]/;

And likewise some of the core modules use it as a trick to create static
variables. However, perl5.10 will have a new warning "Deprecated use of
my() in conditional" that went into blead just a few days ago.

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


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

Date: Mon, 23 Feb 2004 04:03:24 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: trapping file i/o error
Message-Id: <x7smh2fnn7.fsf@mail.sysarch.com>

>>>>> "TvP" == Tassilo v Parseval <tassilo.parseval@rwth-aachen.de> writes:

  TvP> Also sprach Uri Guttman:
  >> <comp.lang.perl removed since it is not a real group. only broken
  >> newsfeeds still carry it. it was removed MANY years ago>
  >> 
  >>>>>>> "BM" == Ben Morrow <usenet@morrow.me.uk> writes:
  >> 
  BM> magic values like $!; other than that, scalar context can be forced with
  BM> scalar() or unary + and list context with parentheses ().
  >> 
  >> list context is not forced with parens. parens in perl are pure
  >> precedence grouping syntax and i believe have (almost) no semantic use
  >> anywhere.

  TvP> Well, take this:

  TvP>     ($a) = @a;

  TvP> What do the parens group here?

  TvP> Or this one:

  TvP>     $a = () = /(.)/g;

  TvP> This is the prototypical example for parens creating list context.

  TvP> In both examples parens are not used to determine precedence but only to
  TvP> enforce list context onto the expression on the right side.

not exactly IMO.

perl -wle '$a,$b = 1, 2, 3 ; print $b'
Useless use of a variable in void context at -e line 1.
Useless use of a constant in void context at -e line 1.
Useless use of a constant in void context at -e line 1.
Name "main::a" used only once: possible typo at -e line 1.
1

that is $a, ($b = 1), 2, 3


perl -wle '$a,$b = (1, 2, 3) ; print $b'
Useless use of a constant in void context at -e line 1.
Useless use of a variable in void context at -e line 1.
Name "main::a" used only once: possible typo at -e line 1.
3

that is $a, ($b = 3).

what i am trying to say is that ($a, $b) = (1) is really parens grouping
$a, $b so they can be assigned together and that is what creates list
context. the parens don't force it but they are syntax allow it to be
provided to the right side. at a pure syntax level, parens are just
grouping. when you have a group (which is a list and can be made in many
ways by syntax) it provides list context for the appropriate nearby
expression. it is a subtle and not always interesting point but i just
want to separate syntax from semantics. list context is a semantic thing
and parens are a syntax thing. we know parens don't always cause list
context and my point is that they never do since they are a syntactic
element.

perl -wle '($a,$b)'
Useless use of a variable in void context at -e line 1.
Useless use of a variable in void context at -e line 1.
Name "main::a" used only once: possible typo at -e line 1.
Name "main::b" used only once: possible typo at -e line 1.

notice that both of those are in void context. only when you assign to a
a paren'ed list do you get list context on the right of =. so = has as much
to do with this as parens do. and you have to have a proper list value
on the right side to make it work as well:

perl -wle '($a,$b) = 1, 2 ; print "$a|$b"'
Useless use of a constant in void context at -e line 1.
Use of uninitialized value in concatenation (.) or string at -e line 1.
1|

that is a case where you have parens on the left side of = and they
don't provide a list context. this is because 1,2 can never be a list
without parens to group the numbers.

hope this clears things up.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: 23 Feb 2004 07:47:55 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: trapping file i/o error
Message-Id: <c1cb7b$5o7$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Uri Guttman:

>>>>>> "TvP" == Tassilo v Parseval <tassilo.parseval@rwth-aachen.de> writes:
> 
>  TvP> Also sprach Uri Guttman:
>  >> <comp.lang.perl removed since it is not a real group. only broken
>  >> newsfeeds still carry it. it was removed MANY years ago>
>  >> 
>  >>>>>>> "BM" == Ben Morrow <usenet@morrow.me.uk> writes:
>  >> 
>  BM> magic values like $!; other than that, scalar context can be forced with
>  BM> scalar() or unary + and list context with parentheses ().
>  >> 
>  >> list context is not forced with parens. parens in perl are pure
>  >> precedence grouping syntax and i believe have (almost) no semantic use
>  >> anywhere.
> 
>  TvP> Well, take this:
> 
>  TvP>     ($a) = @a;
> 
>  TvP> What do the parens group here?
> 
>  TvP> Or this one:
> 
>  TvP>     $a = () = /(.)/g;
> 
>  TvP> This is the prototypical example for parens creating list context.
> 
>  TvP> In both examples parens are not used to determine precedence but only to
>  TvP> enforce list context onto the expression on the right side.
> 
> not exactly IMO.
> 
> perl -wle '$a,$b = 1, 2, 3 ; print $b'
> Useless use of a variable in void context at -e line 1.
> Useless use of a constant in void context at -e line 1.
> Useless use of a constant in void context at -e line 1.
> Name "main::a" used only once: possible typo at -e line 1.
> 1
> 
> that is $a, ($b = 1), 2, 3
> 
> 
> perl -wle '$a,$b = (1, 2, 3) ; print $b'
> Useless use of a constant in void context at -e line 1.
> Useless use of a variable in void context at -e line 1.
> Name "main::a" used only once: possible typo at -e line 1.
> 3
> 
> that is $a, ($b = 3).
> 
> what i am trying to say is that ($a, $b) = (1) is really parens grouping
> $a, $b so they can be assigned together and that is what creates list
> context. the parens don't force it but they are syntax allow it to be
> provided to the right side. at a pure syntax level, parens are just
> grouping. when you have a group (which is a list and can be made in many
> ways by syntax) it provides list context for the appropriate nearby
> expression. it is a subtle and not always interesting point but i just
> want to separate syntax from semantics. list context is a semantic thing
> and parens are a syntax thing. we know parens don't always cause list
> context and my point is that they never do since they are a syntactic
> element.

Debatable, I'd say. Your examples always involve more than one variable
on the left side. In this case, you need parens to clear up precedence.
But when I take those two syntactically correct statements

    $a	 = @a;
    ($a) = @a;

and compare them to, say, two syntactically correct C-statements:

    a	= b;
    (a) = b;

then it should become obvious that parens in Perl at times do have a
semantic meaning whereas in C they are purely syntactic.

> perl -wle '($a,$b)'
> Useless use of a variable in void context at -e line 1.
> Useless use of a variable in void context at -e line 1.
> Name "main::a" used only once: possible typo at -e line 1.
> Name "main::b" used only once: possible typo at -e line 1.
> 
> notice that both of those are in void context. only when you assign to a
> a paren'ed list do you get list context on the right of =. so = has as much
> to do with this as parens do. and you have to have a proper list value
> on the right side to make it work as well:
> 
> perl -wle '($a,$b) = 1, 2 ; print "$a|$b"'
> Useless use of a constant in void context at -e line 1.
> Use of uninitialized value in concatenation (.) or string at -e line 1.
> 1|

Ah, but you can't always know what your right side is doing at all:

    sub function {
	if (wantarray) { print "foo" }
	else	       { print "bar" }
    }
    ?? = function(@args);

You cannot deduce from the syntax whether function() will print 'foo' or
'bar'. Strictly speaking 

    $var = function();
    @var = function();

are identical syntax-wise. In the Perl grammar, both are covered by one
rule:

    term ASSIGNOP term

That means that both

    $a

and

    ($a)

are a 'term'. All they do is differ in their semantics. You can always
use one in the place of the other without harming the syntactic
correctness of your program. Whereas the left side of

    $a, $b = 1, 2, 3;

is not a 'term' at all. The above is matched by 'argexpr' where '$a', '$b
= 1', '2' and '3' are separate 'term's.

The conclusion has to be that '()' are both syntactic and semantic
indicators. They are syntactic where they clear up precedence (and hence
make a whole statement be matched by a different rule). But in the case
where they remain in the same rule they have a semantic meaning.

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


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

Date: Mon, 23 Feb 2004 02:31:54 GMT
From: cnhyf-1076907600@usenet.etext.org (Paul Southworth)
Subject: use Net::protoent no longer works w/ FreeBSD perl 5.6.1
Message-Id: <uCd_b.514$WC3.9386@ord-read.news.verio.net>

use Net::protoent;

This statement works with FreeBSD 4.8's default perl 5.005_03 but not with
perl 5.6.1 (built from FreeBSD ports).  What happened and where can
I learn about the changes?

# uname -r
4.8-RELEASE-p13

[Trying perl 5.005_03]

# use.perl system
# perl -e 'use Net::protoent;'

[Trying perl 5.6.1]

# use.perl port
# perl -e 'use Net::protoent;'
'getproto' is not a valid variable name at /usr/local/lib/perl5/5.6.1/Net/protoent.pm line 12
BEGIN failed--compilation aborted at /usr/local/lib/perl5/5.6.1/Net/protoent.pm line 12.
Compilation failed in require at -e line 1.
BEGIN failed--compilation aborted at -e line 1.

Email Cc: of any clues would be appreciated.

--Paul


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

Date: Mon, 23 Feb 2004 03:06:15 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: use Net::protoent no longer works w/ FreeBSD perl 5.6.1
Message-Id: <c1bqn7$oa8$1@wisteria.csv.warwick.ac.uk>


cnhyf-1076907600@usenet.etext.org (Paul Southworth) wrote:
> use Net::protoent;
> 
> This statement works with FreeBSD 4.8's default perl 5.005_03 but not with
> perl 5.6.1 (built from FreeBSD ports).  What happened and where can
> I learn about the changes?
> 
> # uname -r
> 4.8-RELEASE-p13
> 
> [Trying perl 5.005_03]
> 
> # use.perl system
> # perl -e 'use Net::protoent;'
> 
> [Trying perl 5.6.1]
> 
> # use.perl port
> # perl -e 'use Net::protoent;'
> 'getproto' is not a valid variable name at /usr/local/lib/perl5/5.6.1/Net/protoent.pm line 12
> BEGIN failed--compilation aborted at /usr/local/lib/perl5/5.6.1/Net/protoent.pm line 12.
> Compilation failed in require at -e line 1.
> BEGIN failed--compilation aborted at -e line 1.

Can you show us about the first 20 lines of /usr/local/.../protoent.pm?

> Email Cc: of any clues would be appreciated.

No, sorry. This is Usenet.

Ben

-- 
perl -e'print map {/.(.)/s} sort unpack "a2"x26, pack "N"x13,
qw/1632265075 1651865445 1685354798 1696626283 1752131169 1769237618
1801808488 1830841936 1886550130 1914728293 1936225377 1969451372
2047502190/'                                                 # ben@morrow.me.uk


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

Date: Mon, 23 Feb 2004 03:30:09 GMT
From: cnhyf-1076907600@usenet.etext.org (Paul Southworth)
Subject: Re: use Net::protoent no longer works w/ FreeBSD perl 5.6.1
Message-Id: <5te_b.518$WC3.9411@ord-read.news.verio.net>

In article <c1bqn7$oa8$1@wisteria.csv.warwick.ac.uk>,
Ben Morrow  <usenet@morrow.me.uk> wrote:
>
>cnhyf-1076907600@usenet.etext.org (Paul Southworth) wrote:
>> use Net::protoent;
>> 
>> This statement works with FreeBSD 4.8's default perl 5.005_03 but not with
>> perl 5.6.1 (built from FreeBSD ports).  What happened and where can
>> I learn about the changes?
>> 
>> # uname -r
>> 4.8-RELEASE-p13
>> 
>> [Trying perl 5.005_03]
>> 
>> # use.perl system
>> # perl -e 'use Net::protoent;'
>> 
>> [Trying perl 5.6.1]
>> 
>> # use.perl port
>> # perl -e 'use Net::protoent;'
>> 'getproto' is not a valid variable name at /usr/local/lib/perl5/5.6.1/Net/protoent.pm line 12
>> BEGIN failed--compilation aborted at /usr/local/lib/perl5/5.6.1/Net/protoent.pm line 12.
>> Compilation failed in require at -e line 1.
>> BEGIN failed--compilation aborted at -e line 1.
>
>Can you show us about the first 20 lines of /usr/local/.../protoent.pm?

Yes!

$ head -20 /usr/local/lib/perl5/5.6.1/Net/protoent.pm
package Net::protoent;
use strict;

use 5.005_64;
our(@EXPORT, @EXPORT_OK, %EXPORT_TAGS);
BEGIN {
    use Exporter   ();
    @EXPORT      = qw(getprotobyname getprotobynumber getprotoent);
    @EXPORT_OK   = qw( $p_name @p_aliases $p_proto getproto );
    %EXPORT_TAGS = ( FIELDS => [ @EXPORT_OK, @EXPORT ] );
}
use vars      @EXPORT_OK;

# Class::Struct forbids use of @ISA
sub import { goto &Exporter::import }

use Class::Struct qw(struct);
struct 'Net::protoent' => [
   name         => '$',
   aliases      => '@',



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

Date: 23 Feb 2004 04:01:47 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: use Net::protoent no longer works w/ FreeBSD perl 5.6.1
Message-Id: <slrnc3iupb.csb.sholden@flexal.cs.usyd.edu.au>

On Mon, 23 Feb 2004 03:30:09 GMT,
	Paul Southworth <cnhyf-1076907600@usenet.etext.org> wrote:
> In article <c1bqn7$oa8$1@wisteria.csv.warwick.ac.uk>,
> Ben Morrow  <usenet@morrow.me.uk> wrote:
>>
>>cnhyf-1076907600@usenet.etext.org (Paul Southworth) wrote:
>>> use Net::protoent;
>>> 
>>> This statement works with FreeBSD 4.8's default perl 5.005_03 but not with
>>> perl 5.6.1 (built from FreeBSD ports).  What happened and where can
>>> I learn about the changes?
>>> 
>>> # uname -r
>>> 4.8-RELEASE-p13
>>> 
>>> [Trying perl 5.005_03]
>>> 
>>> # use.perl system
>>> # perl -e 'use Net::protoent;'
>>> 
>>> [Trying perl 5.6.1]
>>> 
>>> # use.perl port
>>> # perl -e 'use Net::protoent;'
>>> 'getproto' is not a valid variable name at /usr/local/lib/perl5/5.6.1/Net/protoent.pm line 12
>>> BEGIN failed--compilation aborted at /usr/local/lib/perl5/5.6.1/Net/protoent.pm line 12.
>>> Compilation failed in require at -e line 1.
>>> BEGIN failed--compilation aborted at -e line 1.
>>
>>Can you show us about the first 20 lines of /usr/local/.../protoent.pm?
> 
> Yes!
> 
> $ head -20 /usr/local/lib/perl5/5.6.1/Net/protoent.pm
> package Net::protoent;
> use strict;
> 
> use 5.005_64;
> our(@EXPORT, @EXPORT_OK, %EXPORT_TAGS);
> BEGIN {
>     use Exporter   ();
>     @EXPORT      = qw(getprotobyname getprotobynumber getprotoent);
>     @EXPORT_OK   = qw( $p_name @p_aliases $p_proto getproto );
>     %EXPORT_TAGS = ( FIELDS => [ @EXPORT_OK, @EXPORT ] );
> }


> use vars      @EXPORT_OK;

Due to @EXPORT_OK being used as a list of variable names it can't include
the function, moving the function to @EXPORT seems the simplest solution.

On the perl 5.6.1 on both linux and Solaris machines here the same problem
exists, the 5.8.3 install of perl works fine, and looking at its copy
of that file "getproto" has been moved to @EXPORT.

On the perl 5.005_02 here the "getproto" function also isn't in the
@EXPORT_OK list (though it also isn't in the @EXPORT list), so I guess you've
stumbled across a bug that was fixed sometime between 5.6.1 and 5.8.3 and
intoduced sometime between 5.005_03 and 5.6.1... I'd take a stab and guess
at the 5.005 -> 5.6 and 5.6 -> 5.8 points if I had to start looking...

So upgrade :) 

Or just move it from @EXPORT_OK to @EXPORT...

-- 
Sam Holden


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

Date: Mon, 23 Feb 2004 05:19:19 GMT
From: Beable van Polasm <beable+unsenet@beable.com.invalid>
Subject: Re: Why is Perl losing ground?
Message-Id: <xd1xomnzkq.fsf@dingo.beable.com>

use63net@yahoo.com (Unknown Poster) writes:
>
> Beable van Polasm <beable+unsenet@beable.com.invalid> wrote in
> message news:<ee8yj1ur2v.fsf@dingo.beable.com>...
> 
> > 
> > Have you tried using one of these modules: Class::Struct,
> > Class::MethodMaker, or Class::MakeMethods?
> 
> This is a good example of why Perl is losing ground as
> object-oriented methods become more popular.

Is it? Have you done a survey?

> There are simply too many approaches to object-oriented programming.
> In addition to these, and other similar modules that are sure to
> come, there's autloading, closures, "use fields", etc.  So, before
> you can even start, if you want to be thorough, you have to
> investigate all these approaches and decide on some criteria that a
> choice will be made on.

OH NO! You might have to make a DECISION! Programming was RUINED!

> Then, there's the problem of integrating your OO code with that
> produced by another team /department / company.  The methodology
> will more than likely be so different as to make this task a real
> bear.

Uh huh. Have you ever looked at CPAN? There are many object oriented
Perl modules on there, and it is really quite easy to integrate them.
I haven't noticed any integration problems caused by different
methodology. For example, I can easily integrate XML::Writer with
IO::File. Why should I even care what methodolgy the authors used?

When you get right down to it, you have objects which contain data,
and supply methods you can use to operate on the data. Who cares what
the author does inside the black box of the classes they write? What
difference does it make if they used Class::MethodMaker or
Class::MakeMethods?


-- 
   


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

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.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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


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