[22699] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4920 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu May 1 09:06:08 2003

Date: Thu, 1 May 2003 06:05:08 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 1 May 2003     Volume: 10 Number: 4920

Today's topics:
        Announcement: The regex coach <edi@agharta.de>
    Re: Announcement: The regex coach <goedicke@goedsole.com>
    Re: built in function 'map' examples? <barryk2@SPAM-KILLER.mts.net>
    Re: CPAN Solaris problem <goedicke@goedsole.com>
    Re: Equivalent for ksh select? <simon.oliver@nospam.umist.ac.uk>
        Get somthing between ( ) from a long string - how - new <anthony@movielink.net.au>
    Re: Get somthing between ( ) from a long string - how - (Damian James)
    Re: Get somthing between ( ) from a long string - how - <anthony@no_spam.movielink.net.au>
    Re: Get somthing between ( ) from a long string - how - <bigj@kamelfreund.de>
    Re: Get somthing between ( ) from a long string - how - <:-@hotmail.com>
    Re: Is it possible to pass @somethig and $something_els <REMOVEsdnCAPS@comcast.net>
    Re: Parsing multiple files and mixing the data <r1534c@motorola.com>
        Proposed new Usenet group forBerkeley DB <paul.marquess@btinternet.com>
        Quickie about a $scalar - convert it <anthony@no_spam.movielink.net.au>
    Re: Quickie about a $scalar - convert it <noreply@gunnar.cc>
    Re: Quickie about a $scalar - convert it <noreply@gunnar.cc>
    Re: Quickie about a $scalar - convert it (Tad McClellan)
    Re: Subtracting strings [long post] (Jay Tilton)
    Re: Subtracting strings [long post] <REMOVEsdnCAPS@comcast.net>
    Re: waste of time <peter_wilson@mail.com>
    Re: what is $@   ? (Villy Kruse)
    Re: What is the best software to run for an aspiring Pe (Thaddeus L. Olczyk)
    Re: What is the best software to run for an aspiring Pe (Thaddeus L. Olczyk)
    Re: What is the best software to run for an aspiring Pe <jurgenex@hotmail.com>
    Re: What is the best software to run for an aspiring Pe <noreply@gunnar.cc>
    Re: What is the best software to run for an aspiring Pe (Tad McClellan)
    Re: What is the best software to run for an aspiring Pe (dalgould)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 01 May 2003 13:18:13 +0200
From: Edi Weitz <edi@agharta.de>
Subject: Announcement: The regex coach
Message-Id: <87smry530q.fsf@bird.agharta.de>

Hi!

This is actually a by-product of something else I wanted to achieve
but I think it might be useful as it is now. The "Regex Coach" is a
GUI application for Windows and Linux which you can use to
interactively test and dissect Perl-compatible regular expressions.

It's at <http://weitz.de/regex-coach/>.

Thanks in advance for constructive criticism and bug reports.

Cheers,
Edi.


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

Date: Thu, 01 May 2003 12:33:12 GMT
From: William Goedicke <goedicke@goedsole.com>
Subject: Re: Announcement: The regex coach
Message-Id: <m33cjy26f1.fsf@mail.goedsole.com>

Dear Edi - 

Edi Weitz <edi@agharta.de> writes:

> Thanks in advance for constructive criticism and bug reports.

You should deliver the source so we can determine it's not a virus.

     Yours -      Billy

============================================================
     William Goedicke     goedicke@goedsole.com            
                          http://www.goedsole.com:8080      
============================================================

          Lest we forget:

Where there's a whim there's a way.

		- William Goedicke


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

Date: Thu, 1 May 2003 08:02:58 -0500
From: Barry Kimelman <barryk2@SPAM-KILLER.mts.net>
Subject: Re: built in function 'map' examples?
Message-Id: <MPG.191ad7008792d30b9897b6@news.mts.net>

[This followup was posted to comp.lang.perl.misc]

In article <HE64to.2qG@news.boeing.com>, Robert 
(robert.j.sipe@boeing.com) says...
> The built in 'map' function is really a powerful tool and have used it a
> fair amount.  However, the syntax of its use is still confusing for the more
> elaborate uses.  I have read the perldoc page and studied the Effective Perl
> Programming book but would like to find more examples to draw upon.
> Pointers to good books, webpages, user examples, FAQs... would be
> appreciated.
> 
> Thanx in advance.

The following line of code uses "map" to find the length of the longest 
element in an array :

$maxlen = (reverse sort { $a <=> $b} map { length $_ } @lines)[0];

The following example constructs a hash from an array :

	@list = ( "hello" , "world" , "goodbye" );
	@indexlist = ( 0 .. $#list );
	%hash1 = ( map { $_ , shift @indexlist } @list );


-- 
---------

Barry Kimelman
Winnipeg, Manitoba, Canada
email : bkimelman@hotmail.com


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

Date: Thu, 01 May 2003 12:15:46 GMT
From: William Goedicke <goedicke@goedsole.com>
Subject: Re: CPAN Solaris problem
Message-Id: <m37k9a2783.fsf@mail.goedsole.com>

Dear Tony - 

Tony Curtis <tony_curtis32@yahoo.com> writes:

> Did you put *your* perl somewhere like /usr/local, but
> CPAN is picking up the perl in /usr/bin/perl which is a (n
> installed) link to /usr/perl5/bin/perl ?

I thought of that and checked it.

bash-2.03$ which perl
/bin/perl
bash-2.03$ ls -l /bin/perl
lrwxrwxrwx   1 root     other         19 Apr 28 16:56 /bin/perl -> /usr/local/bin/perl
bash-2.03$ ls -l /usr/local/bin/perl
-rwxr-xr-x   2 root     other    1074052 Apr 28 16:56 /usr/local/bin/perl
bash-2.03$

That's the one I built alright.  If I go into the directory I built
from I see the following in the Makefile:

bash-2.03$ more Makefile
# Makefile.SH
# This file is derived from Makefile.SH.  Any changes made here will
# be lost the next time you run Configure.
#  Makefile is used to generate makefile.  The only difference
#  is that makefile has the dependencies filled in at the end.
#
#
# I now supply perly.c with the kits, so don't remake perly.c without byacc
BYACC = byacc
CC = gcc
LD = gcc
 ...

Finally I did a chksum comparing the perl in /usr/local/bin with the
one in the build tree:

bash-2.03$ pwd
/export/home/goedicke/src/incoming/perl-5.8.0
bash-2.03$ find . -name perl
 ./t/lib/warnings/perl
 ./t/perl
 ./perl
bash-2.03$ ls -l perl
-rwxr-xr-x   1 root     other    1074052 Apr 28 16:17 perl
bash-2.03$ cksum ./perl
944765182       1074052 ./perl
bash-2.03$ cksum /usr/local/bin/perl
944765182       1074052 /usr/local/bin/perl
bash-2.03$

I'm so confused.

     Yours -      Billy

============================================================
     William Goedicke     goedicke@goedsole.com            
                          http://www.goedsole.com:8080      
============================================================

          Lest we forget:

When you think something nice about someone you're with, tell them
about it.

		- William Goedicke


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

Date: Thu, 01 May 2003 12:50:29 +0100
From: Simon Oliver <simon.oliver@nospam.umist.ac.uk>
Subject: Re: Equivalent for ksh select?
Message-Id: <3EB10A05.6090203@nospam.umist.ac.uk>

Gregg Dameron wrote:
My question:  Is there a Perl module or built-in equivalent for numbered,
multi-column, space-optimizing output?

I don't know of a module but here is a little sub that should get you 
started - it doesn't handle terminal height, only width.  This replaces my 
previous post which used a poor formatting algorithm.

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

# some globals
my $width = 80;
my $gap = 2;

# generate some bugus options:
my @options = map {"Option_$_"} ('A'..'Z');

select_list(\@options);

sub select_list {
   my $aref = shift;
   my $max=0;
   for (@$aref) {
     my $len = length($_);
     $max = $len if $len > $max;
   }
   my $opts = @$aref;
   my $digits = length(@$aref);
   my $w = $digits + 2 + $max;
   my $cols = int( ($width -1 - $w) / ($w + $gap) ) + 1;
   my $rows = int($opts / $cols); $rows++ if $opts % $cols;
   for my $r (1..$rows) {
     for my $c (1..$cols) {
       my $i = $r + ($rows * ($c-1));
       last if $i > $opts;
       printf '%*d) %-*s', $digits, $i, $max, $aref->[$i-1];
       print(' ' x $gap) if ($c < $cols);
     }
     printf "\n";
   }
}



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

Date: Thu, 01 May 2003 16:27:09 +1000
From: "Tony" <anthony@movielink.net.au>
Subject: Get somthing between ( ) from a long string - how - newbie Q
Message-Id: <pan.2003.05.01.06.27.04.574297@movielink.net.au>


Hi Guys,

Got a specific problem.

I am reading in lines from a file where each line
comes in this format:

MON 00:00 0 ("text 1","more_text 1","yet_more_text 2")

The stuff between () can be 1 or more " " delimited
text strings.

The stuff between the () needs to be passed on to
a sub routine for processing. 


I use
   
   foreach my $test(<FILEHANDLE>)
   {
   chomp($test);
   my $temp = $test;
   my @array = split(" ",$temp);
   my $day = $array[0];
   my $time = $array[1];
   my $one_digit = $array[2];
   ...
   }

The above is not pretty but gets me the DAY, TIME and 3rd digit.

How do I go about getting out the stuff between () so it can be passed
on to the other part of the program.

I have experimented with cutting the first 12 chars off and using
the rest - not very elegant and unsafe.  is there a more practical
way of attacking this?

I looked at the $1, $2, $3 ... method but the variable length of
what may be inside () scares me a bit (Passing this on to next sub).

Tony

   


-- 
--------------------------------------------------------------
To reply directly send to: anthony AT movielink DOT net DOT au
Replace AT and DOT with @ and . and mail will get through.
Any spammers will be persued until they get booted off the net



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

Date: 1 May 2003 07:03:34 GMT
From: damian@qimr.edu.au (Damian James)
Subject: Re: Get somthing between ( ) from a long string - how - newbie Q
Message-Id: <slrnbb1hm5.6dl.damian@puma.qimr.edu.au>

On Thu, 01 May 2003 16:27:09 +1000, Tony said:
>...
>MON 00:00 0 ("text 1","more_text 1","yet_more_text 2")
>...
>The stuff between the () needs to be passed on to
>a sub routine for processing. 
>
>I use
>   foreach my $test(<FILEHANDLE>)
>   {
>   chomp($test);
>   my $temp = $test;
>   my @array = split(" ",$temp);
>   my $day = $array[0];
>   my $time = $array[1];
>   my $one_digit = $array[2];
>   ...
>   }
>
>The above is not pretty but gets me the DAY, TIME and 3rd digit.
>
>How do I go about getting out the stuff between () so it can be passed
>on to the other part of the program.
>
>I have experimented with cutting the first 12 chars off and using
>the rest - not very elegant and unsafe.  is there a more practical
>way of attacking this?

Have another look at the perlfunc entry for split():

%perldoc -f split
  split /PATTERN/,EXPR,LIMIT
    ...
    If LIMIT is specified and positive, splits into no
    more than that many fields (though it may split into
    fewer)... 

while (my $test = <FH>) {
   chomp $test;
   my( $day, $time, $one_digit, $parens ) = split / /, $test, 4;
   ... 
}

Cheers,
Damian


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

Date: Thu, 01 May 2003 19:49:43 +1000
From: "Tony" <anthony@no_spam.movielink.net.au>
Subject: Re: Get somthing between ( ) from a long string - how - newbie Q
Message-Id: <pan.2003.05.01.09.49.43.144992@no_spam.movielink.net.au>


Still some problem...can not convert to @array properly

On Thu, 01 May 2003 07:03:34 +0000, Damian James wrote:

> On Thu, 01 May 2003 16:27:09 +1000, Tony said:
>>...
>>MON 00:00 0 ("text 1","more_text 1","yet_more_text 2")

The split with a LIMIT set to 4 like this worked..
   foreach my $test(<FILEHANDLE>)
   {
   chomp($test);
   my $temp = $test;
   my @array = split(" ",$temp,4);
   my $day = $array[0];
   my $time = $array[1];
   my $one_digit = $array[2];
   my $list = $array[3];
   ...
   }

This is smart - now I have the DAY, TIME, DIGIT and a
scalar with ("text 1","more_text 1","yet_more_text 2")
in it.

> Have another look at the perlfunc entry for split():

I did, works a charm, but...

The list of my text is a $scalar string.

I need every part between the " " to be a seperate $scalar
or an @array list so it can be passed to anoter sub for processing.

I could pass the $scalar and process it at the "other end" but
the problem remains that assigning to an @array by means of
splitting causes it to be split like

'("text'  '1","more_text' '1","yet_more_text' '2")'

This is a mess though..

I am hoping there is a way other than using lots of text
manipulation to fix it up. 

The single digit after each text string belongs to that
specific text string.

Tony

> %perldoc -f split
>   split /PATTERN/,EXPR,LIMIT
>     ...
>     If LIMIT is specified and positive, splits into no
>     more than that many fields (though it may split into
>     fewer)... 
> 
> while (my $test = <FH>) {
>    chomp $test;
>    my( $day, $time, $one_digit, $parens ) = split / /, $test, 4;
>    ... 
> }
> 
> Cheers,
> Damian

-- 
--------------------------------------------------------------
To reply directly send to: anthony AT movielink DOT net DOT au
Replace AT and DOT with @ and . and mail will get through.
Any spammers will be persued until they get booted off the net



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

Date: Thu, 01 May 2003 11:40:01 +0200
From: "Janek Schleicher" <bigj@kamelfreund.de>
Subject: Re: Get somthing between ( ) from a long string - how - newbie Q
Message-Id: <pan.2003.05.01.09.38.59.577921@kamelfreund.de>

Tony wrote at Thu, 01 May 2003 16:27:09 +1000:

> I am reading in lines from a file where each line
> comes in this format:
> 
> MON 00:00 0 ("text 1","more_text 1","yet_more_text 2")
> 
> The stuff between () can be 1 or more " " delimited
> text strings.
> 
> The stuff between the () needs to be passed on to
> a sub routine for processing. 
> 
> [Snipped your snippet]
> 
> How do I go about getting out the stuff between () so it can be passed
> on to the other part of the program.
> 

That's a job for regexes:

my $part_in_brackets = $string           =~ /\( (.*) \)/x;
my @elements         = $part_in_brackets =~ /"(.*?)"/g;


BTW, it could be more complicated if there are also some elements
containing a ", e.g. as "text "" 1" (in standard csv way) or
as "text \" 1" (in standard c/c++ way).
In these cases I would rather you to use any of the CSV modules,
e.g. Text::CSV or Text::CSV_XS from CPAN.


Greetings,
Janek


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

Date: Thu, 01 May 2003 22:01:48 +1000
From: :- <:-@hotmail.com>
Subject: Re: Get somthing between ( ) from a long string - how - newbie Q
Message-Id: <3EB10CAC.7698BDA3@hotmail.com>

Tony wrote:
> 
> Hi Guys,
> 
> Got a specific problem.
> 
> I am reading in lines from a file where each line
> comes in this format:
> 
> MON 00:00 0 ("text 1","more_text 1","yet_more_text 2")
> 
> The stuff between () can be 1 or more " " delimited
> text strings.
> 
> The stuff between the () needs to be passed on to
> a sub routine for processing.
> 
> I use
> 
>    foreach my $test(<FILEHANDLE>)
>    {
>    chomp($test);
>    my $temp = $test;
>    my @array = split(" ",$temp);
>    my $day = $array[0];
>    my $time = $array[1];
>    my $one_digit = $array[2];
>    ...
>    }
> 
> The above is not pretty but gets me the DAY, TIME and 3rd digit.
> 
> How do I go about getting out the stuff between () so it can be passed
> on to the other part of the program.
> 
> I have experimented with cutting the first 12 chars off and using
> the rest - not very elegant and unsafe.  is there a more practical
> way of attacking this?
> 
> I looked at the $1, $2, $3 ... method but the variable length of
> what may be inside () scares me a bit (Passing this on to next sub).
> 

Hope this will help...

#!/bin/perl
use strict;
use warnings;

my $infile="something.log";
my ($part1, $part2);
my ($day, $time, $one_digit);

sub something($) {
  my $str = shift;
  my @array = split(/\,/, $str);
  for(my $i=0; $i<scalar(@array); $i++) {
    $array[$i] =~ tr/\"//d;
    printf("array[$i]:\t$array[$i]\n");
  }
}

open(INFILE, "< $infile") or dir("INFILE: $!");
while(<INFILE>) {
  chomp;
  ($part1, $part2) = split(/\(/, $_);
  $part2 =~ tr/)//d;
  ($day, $time, $one_digit) = split(/ /, $part1);
  printf("day:\t\t$day\ntime:\t\t$time\ndigit:\t\t$one_digit\n");
  something($part2);
  print("\n");
}
close(INFILE);


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

Date: Thu, 01 May 2003 05:01:43 -0500
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Is it possible to pass @somethig and $something_else to sub
Message-Id: <Xns936E3D580EA33sdn.comcast@216.166.71.239>

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

"Rich" <budman85@adelphia.net> wrote in
news:pan.2003.04.30.06.03.50.290055@adelphia.net: 

> Hi,
> 
> Well... there are a few ways...
> 
> 
>      &process( $string, \@list);
> 
>      sub process {
>           my ( $str, $a_ref ) = @_;
>           my @Array = @{$a_ref};
>      }
>      }
>      ------------------------------
>      &process( $string, @list );
>      sub process {
>           my ( $string, @Array ) = shift, @_;
>      }
>      }
> If the list is small, and will always be small, then the 2nd method
is
> fine.  If the @list may grow to be very large, the first method is
> much better, also if you want to pass a hash, use the first
method.

No, the first method is not better.  You're copying all the data both
times.  If the array is large, you do not want to make a copy of it
unless you really have to.  Omit the

        my @Array = @{$a_ref};

line, and access the array via the reference.

Do not use & to invoke functions.

- -- 
Eric
print scalar reverse sort qw p ekca lre reh 
ts uJ p, $/.r, map $_.$", qw e p h tona e;
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.1 (MingW32) - WinPT 0.5.13

iD8DBQE+sPCJY96i4h5M0egRAnPdAKC/2XcQZdXppupwVF+N1roqvhRhbACfbfwg
8lGYjqWolP3fRI8zL/T2j+k=
=ghgu
-----END PGP SIGNATURE-----


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

Date: Thu, 1 May 2003 11:43:57 +0100
From: "Martin McKenny" <r1534c@motorola.com>
Subject: Re: Parsing multiple files and mixing the data
Message-Id: <b8qtcb$9j0$1@newshost.mot.com>


"Martien Verbruggen" <mgjv@tradingpost.com.au> wrote in message
news:slrnbb0kuv.3gj.mgjv@verbruggen.comdyn.com.au...
> On Wed, 30 Apr 2003 18:29:47 +0100,
> Martin McKenny <r1534c@motorola.com> wrote:
> > Hi All,
> >
> > I want to read in the lines of multiple files in parallel in order to
merge
> > the elements of each file.
> >
> > So if we have three files with listed data as follows:
> >
> > File1 contains data: a1 a2 a3
> > File2 contains data: b1 b2 b3
> > File3 contains data: c1 c2 c3
>
> So, each line only contain ones line, correct?
>
> > I want to merge these to get a file containing
> >
> > Output file : a1 b1 c1 a2 b2 c2 a3 b3 c3
>
> Maybe:
>
> perl -wpe 'END { print "\n" } s/\n/ /' file1 file2 file3
>
> This has an extra space at the end of the line, before the \n. If
> that's a problem, it's a bit more work.
>
> > I need to do this as effieciently as possible as the files in question
> > contain hundreds of thousands of data elements.
>
> All on one line?
>
> Martien
> --
>                         |
> Martien Verbruggen      | Begin at the beginning and go on till you
> Trading Post Australia  | come to the end; then stop.
>                         |

Thanks to Tad as his response gave the required result - and is (at least!)
easier on the eye than my solution.

Sorry Martien, I wasn't clear on some info I gave. The files contain the
data elements in a single column. Thus I want to read in an element from a
given row of each file and then output this data in the format of a single
column.

So, in a two file example I have two files f1.txt and f3.txt with data
columns:

f1.txt
a1
a2
a3

f2.txt
b1
b2
b3

And the output needs to be (in a column)

a1
b1
a2
b2
a3
b3

Thanks to you both for your help
Regards,
Martin










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

Date: Thu, 1 May 2003 08:44:44 +0100
From: "Paul Marquess" <paul.marquess@btinternet.com>
Subject: Proposed new Usenet group forBerkeley DB
Message-Id: <3eb0d06c$0$4850$ed9e5944@reading.news.pipex.net>

Folks,

there is an RFD available for a new Usenet group, comp.databases.berkeley-db

It's charter is to deal with all things related to Berkeley DB, including
(but by no means exclusively) the Perl interfaces, namely the DB_File and
BerkeleyDB modules.

If you feel that it would be worthwhile having a Usenet group for these
modules, can I encourage you to comment on the comp.databases.berkeley-db
RFD over in news.groups

cheers
Paul




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

Date: Thu, 01 May 2003 20:34:39 +1000
From: "Tony" <anthony@no_spam.movielink.net.au>
Subject: Quickie about a $scalar - convert it
Message-Id: <pan.2003.05.01.10.34.37.948687@no_spam.movielink.net.au>



Hi Guys,

Q about this:

I have a $scalar containing this:

   ("/path/to/file 1" , "/path/to/other/file 1" , "path/to/new/file 2")

The format is "right" if one could say:

@ar = $scalar

I know you can not do this, the stuff between " " needs to be seperated
and put in a list as seperate enteties.

if I had:

@ar = ("/path/to/file 1" , "/path/to/other/file 1" , "path/to/new/file 2")

I could pick any string out by saying:

$my_string = $ar[1];

or

@my_values = @ar[0,1];



However the scalar at the top is a "literal' string and
everything is one list of characters that can not be
seperated.

Is there a way of easily converting this to become the equivelent
of @ar above so it can be processed?

Tony






-- 
--------------------------------------------------------------
To reply directly send to: anthony AT movielink DOT net DOT au
Replace AT and DOT with @ and . and mail will get through.
Any spammers will be persued until they get booted off the net



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

Date: Thu, 01 May 2003 13:10:06 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Quickie about a $scalar - convert it
Message-Id: <b8qvat$cp9n7$1@ID-184292.news.dfncis.de>

Tony wrote:
> I have a $scalar containing this:
> 
>    ("/path/to/file 1" , "/path/to/other/file 1" , "path/to/new/file 2")

<snip>

> Is there a way of easily converting this to become the equivelent
> of @ar above so it can be processed?

     $scalar =~ s/"\)$//;
     @ar = split /" , "/, substr $string, 2;

Is that what you mean?

/ Gunnar

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: Thu, 01 May 2003 13:11:57 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Quickie about a $scalar - convert it
Message-Id: <b8qveb$cp9n7$2@ID-184292.news.dfncis.de>

Gunnar Hjalmarsson wrote:
>     $scalar =~ s/"\)$//;
>     @ar = split /" , "/, substr $string, 2;

Correction:

     $scalar =~ s/"\)$//;
     @ar = split /" , "/, substr $scalar, 2;

/ Gunnar

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: Thu, 1 May 2003 06:51:24 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Quickie about a $scalar - convert it
Message-Id: <slrnbb22hs.6uu.tadmc@magna.augustmail.com>

Tony <anthony@no_spam.movielink.net.au> wrote:

> I have a $scalar containing this:
> 
>    ("/path/to/file 1" , "/path/to/other/file 1" , "path/to/new/file 2")


Have you seen the Posting Guidelines that are posted here frequently?

    Speak Perl rather than English, when possible
        Perl is much more precise than natural language. Saying it in Perl
        instead will avoid misunderstanding your question or problem.

        Do not say: I have variable with "foo\tbar" in it.

        Instead say: I have $var = "foo\tbar", or I have $var = 'foo\tbar',
        or I have $var = <DATA> (and show the data line).


> Is there a way of easily converting this to become the equivelent
> of @ar above so it can be processed?


-------------------------------
#!/usr/bin/perl
use strict;
use warnings;
use Text::ParseWords;

my $scalar =
   '("/path/to/file 1" , "/path/to/other/file 1" , "path/to/new/file 2")';

my @ar = parse_line( '\s*,\s*', 0, substr($scalar, 1, -1) );

print "[$_]\n" for @ar;
-------------------------------


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


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

Date: Thu, 01 May 2003 05:28:01 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Subtracting strings [long post]
Message-Id: <3eb0af52.917147@news.erols.com>

quantum_mechanic_1964@yahoo.com (Quantum Mechanic) wrote:
: tiltonj@erols.com (Jay Tilton) wrote in message news:<3eaf647b.568817771@news.erols.com>...
: > quantum_mechanic_1964@yahoo.com (Quantum Mechanic) wrote:
: > :
: > : [snip] ...The 2nd string must be a
: > : proper substring of the 1st -- if there are characters in the 2nd
: > : string not in the 1st, or there is an excess of one or more characters
: > : in the 2nd string compared to the 1st, a failing result is returned.
: > 
: > That's not the usual interpretation of "substring," but the
: > explanation is clear enough.
: 
: Sorry. "Subset" doesn't fit very well either. "Sub-anagram"?

I can never think of an adequate name for it either, so I deliberately
neglected to suggest one.  :)

: > The gist of that algorithm is peachy, but the rendition is spaghetti.
: 
: I understand reducing them to one sub, but I'd be interested in more
: commentary on the "spaghetti" comment.

I apologize for my clumsy, blunt wording there.  That was meant to be
not a criticism but a purely subjective comment on style.

Code reuse is a great thing, but where does abstraction become
entanglement?  Having an answer presumes having a measurement.

In my mind, making a hash of letters, subtracting one set of numbers
from another, and creating a string are individually trivial enough
operations that they don't need or deserve to be wrapped in
subroutines.

Because you are more familiar with your program than I, your own mind
will necessarily differ.  Each sub justifies its existence by having
sufficient utility elsewhere in the program--for completely arbitrary
values of "sufficient."

: >             $seen{$_} += $i for $foo[$i] =~ /./g;
:
: Small critique...The RE here will be slower than split, won't it?
:
:               $seen{$_} += $i for split //, $foo[$i];

If use of a regex is the criteria, there is nothing to distinguish the
two techniques, since split()'s first argument is itself a regex.

split(//) may indeed enjoy a speed benefit over m/./g .  The Benchmark
module will give an answer to one who cares to investigate.  A
substantial difference could be explained by split() having been
optimized on that special case more than by its being especially well
suited to the task.

Regardless, the distinction in this case will be another of style more
than it will be one of speed.

: Of course, my overuse of block-style map and grep is a mark against me
: ;) But I like boundary markers.

Consider that "map {BLOCK} LIST" tends to be slower than doing the
same thing with "map EXPR, LIST".  Do you like boundary markers more
than you like speed micro-optimization?



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

Date: Thu, 01 May 2003 05:10:47 -0500
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Subtracting strings [long post]
Message-Id: <Xns936E3EE13AFF7sdn.comcast@216.166.71.239>

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

quantum_mechanic_1964@yahoo.com (Quantum Mechanic) wrote in
news:f233f2f0.0304291952.ccfcad4@posting.google.com:

> I'm working on a puzzle, and I'm looking for a simple, clean way
to
> find the "difference" between 2 strings. The 2nd string must be a
> proper substring of the 1st -- if there are characters in the 2nd
> string not in the 1st, or there is an excess of one or more
characters
> in the 2nd string compared to the 1st, a failing result is
returned.
> 
> For example, 
> 
>   $p = 'baseball';
>   $q = 'blab';
>   $r = string_diff( $p, $q ); # $r eq "seal" [in any order]
> 
> but
> 
>   $p = 'baseball';
>   $q = 'bulb';
>   $r = string_diff( $p, $q ); # $r == 0 because 'u' not in $p
> 
> I'm not really interested in the character order of either the
inputs
> or the outputs.

How about this (untested):

sub string_diff
{
    my ($p,$q) = @_;
    my $test = $q;
    eval "\$test =~ tr/$p//d";   # Remove all p characters from q
    return 0 if length $test;    # Return 0 if there were any left
    eval "\$p =~ tr/$q//d";      # Remove all q characters from p
    return $p;                   # Return it
}

- -- 
Eric
print scalar reverse sort qw p ekca lre reh 
ts uJ p, $/.r, map $_.$", qw e p h tona e;
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.1 (MingW32) - WinPT 0.5.13

iD8DBQE+sPKkY96i4h5M0egRAib0AKCQe38lFnajAPBIZThm0eBEUVWNTQCgmdvh
Uk8ufzuygCZcLcpux3YmCas=
=t1vE
-----END PGP SIGNATURE-----


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

Date: Thu, 1 May 2003 08:17:31 +0000 (UTC)
From: "Peter Wilson" <peter_wilson@mail.com>
Subject: Re: waste of time
Message-Id: <b8ql6r$86o$1@titan.btinternet.com>


"smugbuster" <smugbuster@hotmail.com> wrote in message
news:677cff64.0304300948.7e8878c4@posting.google.com...
> your little newsgroup or whatever you call it is a waste of time for
> anybody trying to learn anything new.
>
> legitimate questions are disparaged, ridiculed, and made fun of.
> what's wrong with you people? you were all newbies once!
>
> my guess is that half of you don't know what you're talking about
> anyway.
>
> don't you have anything better to do than to get online and "flame"
> people that may not have as much knowledge of the subject as you.
> pathetic.
>
> i suggest you get a life. you're all a little too smug for your own
> good.
>
> oh, also, i guess i'm not cool because i don't have a witty quip at
> the end of my message, or use case sensitive words or end plural words
> with a string of "z's."
>
> jack

Im learning a lot from this newsgroup and have found everyone fine.

Stop moaning and find a new group to post on

Pete




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

Date: 01 May 2003 09:51:57 GMT
From: vek@station02.ohout.pharmapartners.nl (Villy Kruse)
Subject: Re: what is $@   ?
Message-Id: <slrnbb1rht.3v3.vek@station02.ohout.pharmapartners.nl>

On Wed, 30 Apr 2003 09:53:11 GMT,
    Randal L. Schwartz <merlyn@stonehenge.com> wrote:


>>>>>> "Ethan" == Ethan Brown <ethan@draupnir.gso.saic.com> writes:
>
>Ethan> I didn't know that either, but I found the answer at:
>
>Ethan> http://www.perldoc.com/perl5.6/pod/perlvar.html
>
>Why did you go all the way out to the web for an answer when
>that same document is also on your disk at "perldoc perlvar"?
>And the document on your disk conforms precisely to the version
>of Perl you have installed, and is not frozen at version 5.6
>of Perl as is the URL you mention.
>
>{sigh}
>


Perhaps because google can't find any answers stored on the local disk.


Villy


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

Date: Thu, 01 May 2003 05:54:15 GMT
From: olczyk@interaccess.com (Thaddeus L. Olczyk)
Subject: Re: What is the best software to run for an aspiring Perl programer?
Message-Id: <3eb0b1db.110486234@nntp.interaccess.com>

On 30 Apr 2003 11:51:32 -0700, dalgould@hotmail.com (dalgould) wrote:

>Hello,
>
>I have a question for anyone who may be able to answer.
>What is the best and most avaiable way of testing my perl script from
>my computer itself and not from my web server.  I would like to test
>my perl script locally on my computer first.  What is the best
>software to run for an aspiring Perl programer, on my home computer?
>
>Im getting a little tired of uploading my perl script to my
>CGI-directory over and over just to debug my script.
>
>thank you in advance for any advice or tips!
>

Ok. My best advice is stopaspiring. Not just on Perl
but on programming altogether. You just don't have
the intelligence.

If you know how CGI works ( and if you don't, why didn't you bother to
learn before writing CGI scripts ), and you know a little bit of Perl,
you would have been able to write the following Perl code:
-----------------------------------------------------------------------------------------
open  OUTPUT,">testscript.sh";
print OUTPUT "export PERLSCRIPT=",$0,"\n"; 

foreach $key (keys %ENV)
{
    print OUTPUT "export ",$key,"=",$ENV{$key},"\n";
}

print OUTPUT 'perl -d $PERLSCRIPT ';

foreach $arg (@ARGV)
{
    print OUTPUT $arg," ";
}

print OUTPUT "\n";
----------------------------------------------------------------------------------------------
Overwrite the perl script on the server with this.
( Make sure there is no testscript.sh on the server to overwrite. If
there is then change the name in the script. )
Do your web request. Then move over the testscript.sh ( or whatever
you renamed it ) to you machine.

Now you just run the script from bash and voila! You are in the
debugger with an environment almost as close as you can get to
the server environment.
If you want to just run the script and not enter the debugger, remove
the -d. Ther are lots of ways you can tweak it, ( For example, you
don't print all the keys, you specify which ones you want set. ) but
this is a good starting point.




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

Date: Thu, 01 May 2003 05:58:20 GMT
From: olczyk@interaccess.com (Thaddeus L. Olczyk)
Subject: Re: What is the best software to run for an aspiring Perl programer?
Message-Id: <3eb1b72a.111845843@nntp.interaccess.com>

On Thu, 01 May 2003 05:54:15 GMT, olczyk@interaccess.com (Thaddeus L.
Olczyk) wrote:

>Now you just run the script from bash and voila! You are in the
>debugger with an environment almost as close as you can get to
>the server environment.
>If you want to just run the script and not enter the debugger, remove
>the -d. Ther are lots of ways you can tweak it, ( For example, you
>don't print all the keys, you specify which ones you want set. ) but
>this is a good starting point.
>
I forgot. I'm a Perl newbie, and it only took me fifteen minutes to
come up with this ( most of it spend reading ). 


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

Date: Thu, 01 May 2003 06:35:33 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: What is the best software to run for an aspiring Perl programer?
Message-Id: <Ve3sa.30478$B61.15694@nwrddc01.gnilink.net>

Thaddeus L. Olczyk wrote:
> On Thu, 01 May 2003 05:54:15 GMT, olczyk@interaccess.com (Thaddeus L.
> Olczyk) wrote:
>
>> Now you just run the script from bash and voila! You are in the
>> debugger with an environment almost as close as you can get to
>> the server environment.
>> If you want to just run the script and not enter the debugger, remove
>> the -d. Ther are lots of ways you can tweak it, ( For example, you
>> don't print all the keys, you specify which ones you want set. ) but
>> this is a good starting point.
>>
> I forgot. I'm a Perl newbie, and it only took me fifteen minutes to
> come up with this ( most of it spend reading ).

Actually, you are re-inventing the wheel. CGI.pm already offers a debug
functionalilty where POST and GET are passed from the command line.

jue




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

Date: Thu, 01 May 2003 10:21:46 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: What is the best software to run for an aspiring Perl programer?
Message-Id: <b8qlf2$cnlle$1@ID-184292.news.dfncis.de>

Thaddeus L. Olczyk wrote:
> Ok. My best advice is stopaspiring. Not just on Perl
> but on programming altogether. You just don't have
> the intelligence.

That statement reveals quite a lot about the (lack of) intelligence 
and ripeness of the one who wrote it. It serves no other purpose.

/ Gunnar

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: Thu, 1 May 2003 06:22:26 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: What is the best software to run for an aspiring Perl programer?
Message-Id: <slrnbb20ri.6uu.tadmc@magna.augustmail.com>

Thaddeus L. Olczyk <olczyk@interaccess.com> wrote:
> On 30 Apr 2003 11:51:32 -0700, dalgould@hotmail.com (dalgould) wrote:

>>What is the best and most avaiable way of testing my perl script from
>>my computer itself and not from my web server.


> Ok. My best advice is stopaspiring. Not just on Perl
> but on programming altogether. You just don't have
> the intelligence.


Bullshit.

Ignorance does not imply a lack of intelligence.


> open  OUTPUT,">testscript.sh";


You should always, yes *always*, check the return value from open():

   open OUTPUT, '>testscript.sh' or die "could not open 'testscript.sh' $!";

most especially when you aspire to instructing others on how to do it.


> print OUTPUT "export PERLSCRIPT=",$0,"\n"; 


   print OUTPUT "export PERLSCRIPT=$0\n";


>     print OUTPUT "export ",$key,"=",$ENV{$key},"\n";


   print OUTPUT "export $key=$ENV{$key}\n";


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


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

Date: 1 May 2003 05:57:16 -0700
From: dalgould@hotmail.com (dalgould)
Subject: Re: What is the best software to run for an aspiring Perl programer?
Message-Id: <a26ee76d.0305010457.4a34dc3d@posting.google.com>

> 
> Ok. My best advice is stopaspiring. Not just on Perl
> but on programming altogether. You just don't have
> the intelligence.
> 

Why does someone always have to be a smartass?  Your posting shows
more of a lack of intelligence.  Everyone has to have a starting point
on another programming language.  Your 15 minutes worth really shows.





> If you know how CGI works ( and if you don't, why didn't you bother to
> learn before writing CGI scripts ), and you know a little bit of Perl,
> you would have been able to write the following Perl code:
> -----------------------------------------------------------------------------------------
> open  OUTPUT,">testscript.sh";
> print OUTPUT "export PERLSCRIPT=",$0,"\n"; 
> 
> foreach $key (keys %ENV)
> {
>     print OUTPUT "export ",$key,"=",$ENV{$key},"\n";
> }
> 
> print OUTPUT 'perl -d $PERLSCRIPT ';
> 
> foreach $arg (@ARGV)
> {
>     print OUTPUT $arg," ";
> }
> 
> print OUTPUT "\n";
> ----------------------------------------------------------------------------------------------
> Overwrite the perl script on the server with this.
> ( Make sure there is no testscript.sh on the server to overwrite. If
> there is then change the name in the script. )
> Do your web request. Then move over the testscript.sh ( or whatever
> you renamed it ) to you machine.
> 
> Now you just run the script from bash and voila! You are in the
> debugger with an environment almost as close as you can get to
> the server environment.
> If you want to just run the script and not enter the debugger, remove
> the -d. Ther are lots of ways you can tweak it, ( For example, you
> don't print all the keys, you specify which ones you want set. ) but
> this is a good starting point.


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

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


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