[21981] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4203 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Dec 2 00:05:39 2002

Date: Sun, 1 Dec 2002 21:05:09 -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           Sun, 1 Dec 2002     Volume: 10 Number: 4203

Today's topics:
    Re: a scope question <goldbb2@earthlink.net>
        ANNOUNCE: Lingua::DetectCyrillic <rudenko@bible.ru>
    Re: calling inherited constructor, is this valid? <goldbb2@earthlink.net>
    Re: Changing the width of the tab <robertbu@hotmail.com>
    Re: disable Unicode in Perl 5.8 ? <pilsl_use@goldfisch.at>
    Re: disable Unicode in Perl 5.8 ? <a.gohr@web.de>
    Re: disable Unicode in Perl 5.8 ? <goldbb2@earthlink.net>
    Re: How to place entire commnad line argument list into <krahnj@acm.org>
    Re: How to place entire commnad line argument list into <spam@thecouch.homeip.net>
    Re: Input record separator <iang@nospam.optonline.net>
    Re: Mime Header Problem (Ben Morrow)
        mysql <darkage@freeshellzzzz.org>
    Re: mysql <goldbb2@earthlink.net>
    Re: mysql <dmeans@the-means.net>
    Re: nortel mmcs call records <goldbb2@earthlink.net>
    Re: Resolving Physical Path <goldbb2@earthlink.net>
    Re: Teaching Perl complex data structures <derek@wedgetail.com>
    Re: text extraction on one line? <goldbb2@earthlink.net>
    Re: text extraction on one line? (Malcolm Dew-Jones)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sun, 01 Dec 2002 19:17:11 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: a scope question
Message-Id: <3DEAA687.3661581F@earthlink.net>

derek chen wrote:
> 
> I can't understand why this would not work. $i is visible to test but
> why test is not aware of $i's chnage?
> 
> my $i=0;

Add a line here saying:

   print \$i, "\n";

> for $i (1 .. 10){

Add another line saying:
   print \$i, "\n";

Because of the peculiar treatement of the loop variable, it is very much
similar to you having done:

   for my $i (1 .. 10) {

Which in effect creates a new lexical of the same name as the old one,
but whose visibility is limited to the for loop, and disappears after.

>     test();
> }
> 
> sub test
> {
>     print "$i\n";     # always print 0
> }

And this of course sees the original $i, not the implicitly redeclared
one with the for loop.

-- 
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
 ."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]


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

Date: Mon, 2 Dec 2002 00:54:40 +0300
From: "Alexei Rudenko" <rudenko@bible.ru>
Subject: ANNOUNCE: Lingua::DetectCyrillic
Message-Id: <3deaa010$1_1@news.teranews.com>

Friends, I have just uploaded to CPAN the stable version of the
package Lingua::DetectCyrillic. It detects 7 Cyrillic codings as
well as the language - Russian or Ukrainian.

Unlike all other similar packages it takes into consideration
particularities of CERTAIN Cyrillic codings - this permits to distinct
very close codings, like win1251 and mac-cyrillic; usually one word is
enough for correct detection.

You can download it and test online at:

http://www.bible.ru/DetectCyrillic

Badly need your feedback!

Thank you in advance!

Alexei Rudenko,
Moscow


****** From the documentation *********

DESCRIPTION

This package permits to detect automatically all live Cyrillic codings
- windows-1251, koi8-r, koi8-u, iso-8859-5, utf-8, cp866,
x-mac-cyrillic, as well as the language - Russian or Ukrainian. It
applies 3 algorithms for detection: formal analysis of alphabet hits,
frequency analysis of words and frequency analysis of 2-letter
combinations.

It also provides routines for conversion between different codings of
Cyrillic texts which can be imported if necessary.

The package permits to detect coding with one or two words only.
Certainly, in case of one word reliability will be low, especially if
you wrote the words for testing completely in lower or uppercase, as
capitalization is a very important attribute for coding detection.
Nethertheless the package correctly recognizes coding in a message
containing one single word, even all lowercase - 'privet' ('hello' in
Russian), 'ivan', 'vodka', 'sputnik'. ;-)))

Ukrainian language will be specified only if the text contains
specific Ukrainian letters.

Performance is good as the analysis passes two stages: on the first
only formal and fast analysis of proper capitalization and alphabet
hit is carried out and only if these data are not enough, the input is
analyzed second time - on frequency dictionaries.







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

Date: Sun, 01 Dec 2002 18:26:14 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: calling inherited constructor, is this valid?
Message-Id: <3DEA9A96.6C702ECA@earthlink.net>

Josef Drexler wrote:
[snip]
> package LWP::FormAgent;
> use base qw(LWP::UserAgent);
> use strict;
> use warnings;
> 
> sub new {
>         my $class = shift;
>         my $self = LWP::UserAgent->new(@_);
>         push @{ $self->requests_redirectable }, 'POST';
>         # ... do some other initialization stuff
>         return bless $self, $class;
> }

You should be coding it like this, instead:

   package LWP::FormAgent;
   use base qw(LWP::UserAgent);
   use strict;
   use warnings;

   sub new {
      my $self = shift()->SUPER::new(@_);
      push @{ $self->requests_redirectable }, 'POST';
      # ... do some other initialization stuff
      return $self;
   }

The LWP::UserAgent constructor should bless the new object into the
appropriate class, based on the first argument... thus, you shouldn't
need to bless it yourself.

Now, you want to know *why* you should let your superclass bless it
appropriately, rather than reblessing it?

Well, for LWP::UserAgent, it's harmless (I think), but for other
classes, it may result in problems.

What happens if, inside the superclass's constructor, it creates a
hashref, blesses it, then calls methods on it to initialize it, then
returns it?  For example, if the superclass's constructor were:

   sub new {
      my $self = bless {}, shift();
      $self->configure(@_);
      return $self;
   }


Suppose that you, the inheritor, want to override the configure method?

If your constructor is:
   sub new {
      my $class = shift();
      my $self = SuperClassName->new(@_);
      # other stuff with $self.
      return bless $self, $class;
   }

Then your overridden 'configure' method won't ever be called, and the
superclass's 'configure' will be called instead.

But if your constructor is:
   sub new {
      my $self = shift()->SUPER::new(@_);
      # other stuff with $self.
      return $self;
   }

Then your overridden 'configure' method WILL get called.

PS: For an example of this, look into the IO::Socket::INET class.  Look
at the 'new' method... where's all the work done?!  Everything is
handled in the parent class's constructor, and in 'configure'.

-- 
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
 ."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]


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

Date: Mon, 02 Dec 2002 04:49:16 GMT
From: "robertbu" <robertbu@hotmail.com>
Subject: Re: Changing the width of the tab
Message-Id: <gDBG9.22503$ic6.20462@nwrddc01.gnilink.net>


"AG" <ag269@columbia.edu> wrote in message
news:6c4429bb.0211302240.10ece4b0@posting.google.com...
> I am trying to output a table of 2 columns using /t formatting:
>
> However, if the length of the word if the first column exceeds 7
> characters, the next column is pushed further then the rest. Which
> leads me to my question:
>
> Is there a way to change the default width of columns from 8 to ,say,
> 12 characters?
>
> Thank you

If your problem can be solved by expanding tabs to spaces using a tab stop
you set, you might take a look at Text::Tabs module or Section 1.7 of the
Perl Cookbook.

== Rob ==

== Rob ==




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

Date: Mon, 2 Dec 2002 00:28:40 +0100
From: peter pilsl <pilsl_use@goldfisch.at>
Subject: Re: disable Unicode in Perl 5.8 ?
Message-Id: <3dea9bd8@e-post.inode.at>

Andreas Gohr wrote:

> Hi all!
> 
> I have a problem with the new unicode behaviour of Perl 5.8. I've read
> already the perldocs perluniintro and perlunicode as well as the Perl
> Locale and Unicode FAQ but I found no way to completely disable the new
> internal string representation as unicode. I have to insert some values
> into a MySQL database and need all strings to be always latin1. The
> program is supposed to run in Perl 5.6 _and_ Perl 5.8 (and maybe in Perl
> 5.004 too) and I need a way to behave always the same.
> Do you have any tips for me?
> 

Like Benjamin said: maybe your problem is *before* or *after* perl. I 
produce (on purpose) loads of unicode-data that is processed by perl and 
stored in a postgres-database. I occassionally use mySQL too and I never 
had any unicode-problems with it.

Mayby you could tell the actual problem you have with unicode.

peter

-- 
peter pilsl
pilsl_@goldfisch.at
http://www.goldfisch.at



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

Date: Mon, 02 Dec 2002 02:33:29 +0100
From: "Andreas Gohr" <a.gohr@web.de>
Subject: Re: disable Unicode in Perl 5.8 ?
Message-Id: <pan.2002.12.02.01.33.20.485018@web.de>

On Sun, 01 Dec 2002 18:05:02 +0000, Benjamin Goldberg wrote:
>> I have to insert some values into a MySQL database and need all
>> strings to be always latin1.
> 
> Umm, why not use the Encode module to convert your strings to latin1?

Because the Encode module is not available in the Perl 5.6 distribution (I
want to avoid too much dependencies on non standard modules)
 
> Or better yet, avoid producing utf8 strings in the first place.

yes that would be great. Unfortunately I use the HTML::Entities module to
decode HTML-Entities and in Perl 5.8 it does produce Unicode instead of
latin1 as in Perl 5.6 :-/

> Don't store data in your strings with character values > 256?

As said above I get them from HTML::Entities
 
> Once it *has* upgraded data to utf8, then of course you may need to
> force it to downgrade it before storing it in your database... but if
> your database is will-designed, it will do it for you.

Well mysql isn't as I found out :-( I currently test for the perl version
and if it is above 5.7 I run some map function on my strings to decode the
unicode back (I found these in somewhere in the docs). But I'm not very
happy with that solution as I would like to avoid utf8 in the first place
as you suggested..
 
> (There are also some functions in the utf8:: namespace which may help).

I still would have to check for the Perl version right?

still puzzled...
Andi



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

Date: Sun, 01 Dec 2002 23:02:37 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: disable Unicode in Perl 5.8 ?
Message-Id: <3DEADB5D.A67C0F96@earthlink.net>

Andreas Gohr wrote:
> 
> On Sun, 01 Dec 2002 18:05:02 +0000, Benjamin Goldberg wrote:
> >> I have to insert some values into a MySQL database and need all
> >> strings to be always latin1.
> >
> > Umm, why not use the Encode module to convert your strings to
> > latin1?
> 
> Because the Encode module is not available in the Perl 5.6
> distribution (I want to avoid too much dependencies on non standard
> modules)
> 
> > Or better yet, avoid producing utf8 strings in the first place.
> 
> yes that would be great. Unfortunately I use the HTML::Entities module
> to decode HTML-Entities and in Perl 5.8 it does produce Unicode
> instead of latin1 as in Perl 5.6 :-/

Hmm... In perl5.8, HTML::Entities produces utf8, but Encode is available
to convert to latin1.  In perl5.6, Encode isn't available, but
HTML::Entities produces latin1 in the first place.

I don't see your problem -- Obviously, you've got to have two code
paths, but that's not especially difficult.

   BEGIN {
       my $have_encode = eval {
         require Encode;
         import  Encode qw(encode);
         1;
      } || 0;
      *HAVE_ENCODE = sub () { $have_encode };
   }

   ... stuff in between ...

   @data = map encode("iso-8859-1", $_), @data
      if HAVE_ENCODE;
   $sth->execute(@data);


> > Don't store data in your strings with character values > 256?
> 
> As said above I get them from HTML::Entities
> 
> > Once it *has* upgraded data to utf8, then of course you may need to
> > force it to downgrade it before storing it in your database... but
> > if your database is will-designed, it will do it for you.
> 
> Well mysql isn't as I found out :-( I currently test for the perl
> version and if it is above 5.7 I run some map function on my strings
> to decode the unicode back (I found these in somewhere in the docs).

That sounds about right.  But instead of testing for the perl version, I
would test for having the presense of Encode.pm.

> But I'm not very happy with that solution as I would like to avoid
> utf8 in the first place as you suggested..

According to the source of HTML::Entities, some elements of the
translation hash table to go from entities to characters are the chr()
of numbers >= 256.

If your data does not contain such entities, then I do not see why your
resultant data would be upgraded to utf8.

Also, you *could* go and modify %HTML::Entities::entity2char and
%HTML::Entities::char2entity, to remove those characters which are in
utf8.  This would be an ugly workaround, but you could do it.

> > (There are also some functions in the utf8:: namespace which may
> > help).
> 
> I still would have to check for the Perl version right?

You could, I suppose, but 'twould be more sensible to simply test for
defined(&utf8::subname).

-- 
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
 ."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]


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

Date: Mon, 02 Dec 2002 02:49:20 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: How to place entire commnad line argument list into a single  stringvariable
Message-Id: <3DEAC9FF.307AF5F9@acm.org>

Chuckster wrote:
> 
> I have a perl script that expects a SQL query as it's command line
> argument. I want to place the entire command line argument into a single
> string. It there an easy way of doing this other than checking the
> length of @ARGV and then building a string in a while/for loop?

my $query = join ' ', @ARGV if @ARGV;


John
-- 
use Perl;
program
fulfillment


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

Date: Sun, 01 Dec 2002 18:41:24 -0500
From: Mina Naguib <spam@thecouch.homeip.net>
Subject: Re: How to place entire commnad line argument list into a single string variable
Message-Id: <3DEA9E24.3040309@thecouch.homeip.net>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1



Chuckster wrote:
| I have a perl script that expects a SQL query as it's command line
| argument. I want to place the entire command line argument into a single
| string. It there an easy way of doing this other than checking the
| length of @ARGV and then building a string in a while/for loop?

Tony answered with a solution.

Another possibility is to pass the SQL string surrounded by quotes to
the perl script.  That will make it quantified as 1 string, instead of
being treated as multiple parameters.


-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQE96p4keS99pGMif6wRAmY7AJ9m8Becdr6PPIHtypcMER2A/0iNyQCg/p1b
tEJp/UF0mrw2yJ2h1VaSN/g=
=g+lH
-----END PGP SIGNATURE-----



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

Date: Mon, 02 Dec 2002 01:12:34 GMT
From: "Ian" <iang@nospam.optonline.net>
Subject: Re: Input record separator
Message-Id: <6syG9.53110$Kk2.16540@news4.srv.hcvlny.cv.net>

Thanks Uri,

That of course works like a charm.  I had thought
of that, but i got hung up on trying to get the IRS
to work.  A previous poster suggested "\n#\n" which
works as well.

As i continue writeing however, your way is better
because i have my record nicely separated into a hash
which i can then pass to a function.

Thanks again.

Ian
"Uri Guttman" <uri@stemsystems.com> wrote in message
news:x7adjs2ni4.fsf@mail.sysarch.com...
> The following message is a courtesy copy of an article
> that has been posted to comp.lang.perl.misc as well.
>
> >>>>> "I" == Ian  <iang@optonline.com> writes:
>
>
>   I> I have a file contianing records. Each Record is separated
>   I> by a single line beginning with a hash (#).  It is possible
>   I> however to have data withing the records to contain a hash.
>
>   I> I have set the $/ to "#" which works fine for files with
>   I> no # in the data.  However I do not read the records correctly
>   I> if I have a "#" embeded in some data.
>
>   I> I have attempted to set the $/ to "#$" and "^#$" and "#/$" with no
>   I> success.
>
> $/ is not a regex but a plain string. this is a known limitation and
> documented. since your record marker is a single line it would be simple
> to do a line by line read and the process when you get a # line
>
> my $record_text ;
> while( my $line = <INPUT> ) {
>
> if ( $line =~ /^#/ ) {
> process_record( $record_text ) ;
> $record_text = '' ;
> next ;
> }
>
> $record_text .= $line ;
> }
>
> uri
>
> --
> Uri Guttman  ------  uri@stemsystems.com  --------
http://www.stemsystems.com
> ----- Stem and Perl Development, Systems Architecture, Design and
Coding ----
> Search or Offer Perl Jobs  ----------------------------
http://jobs.perl.org




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

Date: Sun, 1 Dec 2002 23:44:09 +0000 (UTC)
From: mauzo@mimosa.csv.warwick.ac.uk (Ben Morrow)
Subject: Re: Mime Header Problem
Message-Id: <ase6s9$nb9$1@wisteria.csv.warwick.ac.uk>

"Cold Cathoid" <meme@meme.com> wrote:
>
>"Ron Reidy" <rereidy@indra.com> wrote in message
>news:3DE99F2D.4547E9F3@indra.com...
>> Cold Cathoid wrote:
>> > I am writing a script that grabs a bunch of data from a webform. The
>script
>> > (as cgi of course) takes the incoming form data and creates a SQL
>statement
>> > with which to insert a record into the database. As I slowly create the
>SQL
>> > string I output it to the screen to make sure it's coming along ok. When
>I
>> > have processed about 30 of the form elements I get:
>> >
>> > Server Error
>> > The following error occurred:
>> > The server response MIME header is too long.
>> >
<snip>
>> Do you initialize $insertSQL?
>>
>I hadn't ... but I tried initializing it to $insertsSQL = ""; .... but that
>didn't help

I think this is a CGI error, rather than a Perl error; and the answer is that
you're not printing a Content-type header before the rest of your output so
httpd is scanning your long query to find if it says Content-type and fills up
it's buffer.

Have you got a line like

print <<HTTP;
Status: 200 OK
Content-type: text/plain

HTTP

at the top?

Ben


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

Date: Mon, 2 Dec 2002 11:37:14 +1100
From: "^darkage" <darkage@freeshellzzzz.org>
Subject: mysql
Message-Id: <ase9vr$dck$1@perki.connect.com.au>

does anyone have an example of how to put an array into a mysql database.
I've tired using net::mysql, it works with plain text values but doesn't
work when inserting using a scalar or array.   I've got 6 elements in my
array.

ie. $mysql->query(q{
  INSERT INTO logs (field1, field2, field3, field4, field5, field6) VALUES
($fields[0],$fields[1],$fields[2],$fields[3],$fields[4],$fields[5])
  });


Would someone be able to give me an example please.





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

Date: Sun, 01 Dec 2002 20:19:34 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: mysql
Message-Id: <3DEAB526.4A41127C@earthlink.net>

^darkage wrote:
> 
> does anyone have an example of how to put an array into a mysql
> database.

#! perl -w
use strict;

use DBI ();
use DBD::mysql ();

my $dsn = join(";",
   "DBI:mysql",
   "database=$database",
   "host=$hostname",
   "port=$port",
);

my $dbh = DBI->connect(
   $dsn, $user, $password,
   { RaiseError => 1, AutoCommit => 1 },
) or die "DBI->connect to $dsn failed: $DBI::errstr";

my @fieldnames = "field1" .. "field6";
my @placeholders = ("?") x @fieldnames;

my $sth = $dbh->prepare( do { local $" = ","; qq[
   INSERT INTO logs (@fieldnames) VALUES (@placeholders)
] } );

$sth->execute( @fields[0..5] );

$dbh->disconnect();

__END__
[untested]

-- 
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
 ."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]


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

Date: Sun, 01 Dec 2002 23:35:23 -0500
From: David Means <dmeans@the-means.net>
Subject: Re: mysql
Message-Id: <pan.2002.12.02.04.35.19.632037.29213@the-means.net>

On Sun, 01 Dec 2002 20:19:34 -0500, Benjamin Goldberg wrote:

{ snip } 
> 
> #! perl -w
> use strict;
> 
> use DBI ();
> use DBD::mysql ();
> 
> my $dsn = join(";",
>    "DBI:mysql",
>    "database=$database",
>    "host=$hostname",
>    "port=$port",
> );
> 
> my $dbh = DBI->connect(
>    $dsn, $user, $password,
>    { RaiseError => 1, AutoCommit => 1 },
> ) or die "DBI->connect to $dsn failed: $DBI::errstr";
> 

Where is a FAQ on how to construct this stuff for standard SQL
connections.  Say, Sybase, or MSSQL Server?

-- 
David Means

Real programs don't eat cache.



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

Date: Sun, 01 Dec 2002 20:35:30 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: nortel mmcs call records
Message-Id: <3DEAB8E2.8289859C@earthlink.net>

Sean wrote:
> 
> Hi folks,
> before I go re-inventing the wheel... :-)
> 
> anybody already parsed the records out of a Nortel MMCS telephone
> switch in perl?

What do they look like?

> I had a quick look at the manual and there appear to many different
> types of records so it isn't just a simple parse...

It's possible that although the files aren't simple, they are using some
(already existing) format designed for storing complex data.  Show us
bits of the files, and perhaps we can tell you, "Oh yeah, that's the
<foo> format, and you use module <bar> to parse it."

But it's a bit hard to help parse data without knowing what it looks
like :).

-- 
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
 ."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]


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

Date: Sun, 01 Dec 2002 21:30:36 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Resolving Physical Path
Message-Id: <3DEAC5CC.60EAB126@earthlink.net>

jsmoriss@mvlan.net wrote:
> 
> Hi everyone,
> 
> I've done quite a bit of searching and thinking on this one, but can't
> find a solution. I need to resolve the real/physical path of a file.
> i.e. I have a path which includes several directories and a filename -
> some of these directories, or even the filename, might be symbolic
> links. I need to resolve this path back to the actual physical path.
> Anyone know of a quick/efficient way of doing this?

Not necessarily effcient, but here is a *correct* way of doing it:

   use File::Spec::Functions;
   my $filename = ...;
   my ($volume, $dir, $file) = splitpath( rel2abs( $filename ) );
   my @dir = (splitdir( $dir ), $file);
   my $dir = my $empty = catdir();
   my $fully_resolved;
   while( @dir ) {
      if( @dir ) {
         my $d = catpath($volume, $dir, shift @dir);
         if( -l $d ) {
            defined( my $link = readlink( $d ) )
               or die "Error in readlink( $d ): $!";
            $link = rel2abs( $link, $d );
            ($volume, $dir, my $f) = splitpath( $link );
            unshift @dir, splitdir($dir), $f;
            $dir = $empty;
         }
      } else {
         my $d = catpath( $volume, $dir, '' );
         my $f = catpath( $volume, $dir, shift @dir );
         if( -l $f ) {
            defined( my $link = readlink( $f ) )
               or die "Error in readlink( $f ): $!";
            $link = rel2abs( $link, $d );
            ($volume, $dir, $file) = splitpath( $link );
            unshift @dir, splitdir($dir), $file;
            $dir = $empty;
         }
         $fully_resolved = $f;
      } # end else
   } # end while.
   print $fully_resolved, "\n";
__END__
[untested]  

The use of the File::Spec::Functions stuff is so that it will work on
any OS, not just unix.  I'm not entirely sure I have it written right,
since I don't know how readlink behaves on non-unices, and I'm not sure
whether catpath($volume, $dir, '') is the proper way of creating a fully
qualified path to a directory.

Of course, if one is just doing unix, then one try the following:

   $_ = rel2abs( $_ );
   1 while s[^
      ( (?: [^/]* /? )*? )
      (??{ -l $1 ? "" : "(?!)" })
   ]{
      my $link = $1;
      reverse($link) =~ m[^/?[^/]*(.*)]s;
      rel2abs( readlink($link), scalar reverse($1) );
   };
[untested]

-- 
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
 ."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]


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

Date: Mon, 02 Dec 2002 01:08:47 GMT
From: Derek Thomson <derek@wedgetail.com>
Subject: Re: Teaching Perl complex data structures
Message-Id: <zoyG9.160$_27.4817@news.optus.net.au>

Bart Lateur wrote:
> 
> Say whatever you want, but I find this clumsy. In Perl, you can have it
> both ways.

Yes, I think I'll havve to emphasize the value of this flattening 
behaviour early on. If I try to get people using it, it won't be such a 
suprise. It's tough, though, without a proper training session - I just 
have to help people as they progress as best I can.

> 
> 
> If people want to do Lisp-like stuff in Perl, teach them to always use
> square brackets.
> 

Yes, I've been thinking about doing this, which means introducing 
references earlier. Perhaps that's the problem - I always teach 
references later as that's the way I learned about them.

I started with Learning Perl 2nd Edition, and that doesn't mention 
references at all!

Actually that's not quite true, I did a tiny bit of Perl 4 circa 1995, 
and that didn't even *have* references. I dropped it for that exact 
reason - I couldn't do typical programming tasks easily without support 
for complex data structures. Yes, I know there were various hacks, but I 
didn't like them at all.

--
D.



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

Date: Sun, 01 Dec 2002 23:14:52 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: text extraction on one line?
Message-Id: <3DEADE3C.DFC0D097@earthlink.net>

David Andel wrote:
> 
> Hi
> 
> I like the onliners enabling me to replace text in files, like
> perl -i -p -e 's/search/replace/g' $(find . -type f)
> 
> But I can't figure out how to extract text from files (either by
> writing it to another file or by deleting the text before and after
> the sequence). Say I have a bunch of files containing some text
> between "begin" and "end". Is there a simple solution to extract that
> text (or delete everything before "begin" and after "end") in one line
> or do I have to write a script therefore?

find . -type f | xargs perl -ln0777e 'print /.*?begin(.*?)end.*/$1/s;'

[untested]

Or if you want to shave off a few bytes, and risk the chance that the
output of find will be bigger than your OS's ARG_MAX limit, and if you
don't mind the possibility of some of the filenames containing spaces:

perl -ln0777e 'print /.*?begin(.*?)end.*/$1/s;' $(find . -type f)

[Here in the windows world, every name within "C:/Program Files"
contains a space, so the xargs version would be necessary].

-- 
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
 ."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]


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

Date: 1 Dec 2002 21:00:16 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: text extraction on one line?
Message-Id: <3deae8e0@news.victoria.tc.ca>

David Andel (andel@ifi.unizh.ch) wrote:
: Hi

: I like the onliners enabling me to replace text in files, like perl -i -p 
: -e 's/search/replace/g' $(find . -type f)

: But I can't figure out how to extract text from files (either by writing it 
: to another file or by deleting the text before and after the sequence). Say 
: I have a bunch of files containing some text between "begin" and "end". Is 
: there a simple solution to extract that text (or delete everything before 
: "begin" and after "end") in one line or do I have to write a script 
: therefore?

One possibility is .. (or ...) .  

so the starting point for what you want is

	perl -n -e "print if /begin/../end/"

though you may need to figure out how to use the sequence number return
value to get exactly what you want.



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

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


Administrivia:

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

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

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

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

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


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


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