[24653] in Perl-Users-Digest
Perl-Users Digest, Issue: 6817 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Aug 3 13:56:57 2004
Date: Tue, 3 Aug 2004 10:56:15 -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 Tue, 3 Aug 2004 Volume: 10 Number: 6817
Today's topics:
pattern match with newline (justme)
Re: pattern match with newline (Anno Siegel)
Re: pattern match with newline (Charles DeRykus)
Perl 6: language has "local" variables (ie "dynamic" va (David Combs)
Re: Perl 6: language has "local" variables (ie "dynamic <bik.mido@tiscalinet.it>
Perl debugger in Perl script hierarchy (Volker Nicolai)
Re: Perl debugger in Perl script hierarchy <mritty@gmail.com>
Re: Perl debugger in Perl script hierarchy <jurgenex@hotmail.com>
Re: Perl debugger in Perl script hierarchy (Peter Scott)
Re: Perl debugger in Perl script hierarchy <nospam-abuse@ilyaz.org>
perl graph theory (using Graph::Directed) <iotarhorho@REMOV3hotmail.com>
Re: perl graph theory (using Graph::Directed) (Greg Bacon)
Re: perl graph theory (using Graph::Directed) <iotarhorho@REMOV3hotmail.com>
Perl returning mucky characters to a shell <david@tvisnospam.co.uk>
Re: Perl returning mucky characters to a shell (Anno Siegel)
Re: Perl returning mucky characters to a shell <bik.mido@tiscalinet.it>
Re: Perl returning mucky characters to a shell <david@tvisnospam.co.uk>
Re: Perl returning mucky characters to a shell <bik.mido@tiscalinet.it>
perl script to manage internal address mailing lists <samm@chepnt.net>
Re: perl script to manage internal address mailing list <thundergnat@hotmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 27 Jul 2004 20:07:27 -0700
From: eight02645999@yahoo.com (justme)
Subject: pattern match with newline
Message-Id: <c0837966.0407271907.2a3ff66c@posting.google.com>
hi
i have a file like this
---> STOR ABC.DEF.M.Y1234.MMMMM.TTTTTT
125 Storing data set ABC.DEF.M.Y1234.MMMMM.TTTTTT
250 Transfer completed successfully.
---> QUIT
221 Quit command received. Goodbye.
MMMMM.TTTTTT are dynamic
i want to grab just the lines :
125 Storing data set ABC.DEF.M.Y1234.MMMMM.TTTTTT
250 Transfer completed successfully.
so i did up a code
open(FILE,"test.dat") or die "Cannot open test.dat\n";
while ( <FILE> )
{
print "Got it" if $_ =~ /^125 Storing data set ABC.DEF.M.Y.*\n250
Transfer completed successfully.$/m
}
but it does not work.
can someone correct my mistakes on the regexp. thanks.
------------------------------
Date: 28 Jul 2004 08:47:12 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: pattern match with newline
Message-Id: <ce7p6g$ll$2@mamenchi.zrz.TU-Berlin.DE>
justme <eight02645999@yahoo.com> wrote in comp.lang.perl.misc:
> hi
>
> i have a file like this
>
> ---> STOR ABC.DEF.M.Y1234.MMMMM.TTTTTT
> 125 Storing data set ABC.DEF.M.Y1234.MMMMM.TTTTTT
> 250 Transfer completed successfully.
> ---> QUIT
> 221 Quit command received. Goodbye.
>
> MMMMM.TTTTTT are dynamic
>
> i want to grab just the lines :
> 125 Storing data set ABC.DEF.M.Y1234.MMMMM.TTTTTT
> 250 Transfer completed successfully.
>
> so i did up a code
>
> open(FILE,"test.dat") or die "Cannot open test.dat\n";
> while ( <FILE> )
> {
> print "Got it" if $_ =~ /^125 Storing data set ABC.DEF.M.Y.*\n250
> Transfer completed successfully.$/m
>
> }
>
> but it does not work.
"Does not work?" You have been around long enough to know that is
insufficient as an error description. It is just rude to expect
your readers to analyze the code to find out what it is you're
complaining about.
When you read a file line-wise, as you do, there cannot be two lines
in a single string. Your pattern assumes that there are. Also,
the dots in the pattern need quoting.
my $got_one;
while ( <DATA> ) {
print "got it\n" if $got_one and
/^250 Transfer completed successfully\./;
$got_one = /^125 Storing data set ABC\.DEF\.M\.Y\./;
}
Anno
------------------------------
Date: Thu, 29 Jul 2004 21:47:59 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: pattern match with newline
Message-Id: <I1Mv7z.Irq@news.boeing.com>
In article <c0837966.0407271907.2a3ff66c@posting.google.com>,
justme <eight02645999@yahoo.com> wrote:
>hi
>
>i have a file like this
>
>---> STOR ABC.DEF.M.Y1234.MMMMM.TTTTTT
>125 Storing data set ABC.DEF.M.Y1234.MMMMM.TTTTTT
>250 Transfer completed successfully.
>---> QUIT
>221 Quit command received. Goodbye.
>
>MMMMM.TTTTTT are dynamic
>
>i want to grab just the lines :
>125 Storing data set ABC.DEF.M.Y1234.MMMMM.TTTTTT
>250 Transfer completed successfully.
>
>so i did up a code
>
>open(FILE,"test.dat") or die "Cannot open test.dat\n";
>while ( <FILE> )
>{
> print "Got it" if $_ =~ /^125 Storing data set ABC.DEF.M.Y.*\n250
>Transfer completed successfully.$/m
>
>}
>
>but it does not work.
The read only processes a line at a time so the
regex'll never match both lines.
Something like this will work:
my $qr1 = '^125 Storing data set ABC.DEF.M.Y1234.MMMMM.TTTTTT$';
my $qr2 = '^250 Transfer completed successfully.$';
while (<DATA>) {
if (/$qr1/ ) {
{ unless (eof) {
$_ = <DATA>;
if ( /$qr2/ ) {
print "got it ($.)\n";
} else {
/$qr1/ ? redo : next;
}
}
}
}
}
__END__
...
250 Transfer completed successfully.
125 Storing data set ABC.DEF.M.Y1234.MMMMM.TTTTTT
...
--
Charles DeRykus
------------------------------
Date: 31 Jul 2004 20:42:47 -0400
From: dkcombs@panix.com (David Combs)
Subject: Perl 6: language has "local" variables (ie "dynamic" vars)?
Message-Id: <cehea7$199$1@panix2.panix.com>
In a bookstore a few days ago, looked at 2nd edition
of Perl 6 (O'Reilly).
Saw dynamic vars in the interpreter-language, but
no mention in the perl-6 language.
Is it there? Better, does perl-6 have such a dcl?
For when it's needed, is very nice indeed;
saves having to write lots of exceptions-code.
Thanks,
David
------------------------------
Date: Mon, 02 Aug 2004 00:52:05 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Perl 6: language has "local" variables (ie "dynamic" vars)?
Message-Id: <fvnqg05gmjpa2aphv60kvor2n0o2bk55fl@4ax.com>
On 31 Jul 2004 20:42:47 -0400, dkcombs@panix.com (David Combs) wrote:
>Saw dynamic vars in the interpreter-language, but
>no mention in the perl-6 language.
>
>Is it there? Better, does perl-6 have such a dcl?
>
>For when it's needed, is very nice indeed;
>saves having to write lots of exceptions-code.
I'm not sure if I understand what you mean. AIUI Perl6 will finally
get rid of the two current mostly orthogonal sets of variables
(pacakge and lexical). What is now C<local> will be C<temp>. But then
since you talk about exceptions, you may also be interested in
hypotheticals, continuations and other marvels...
Michele
--
you'll see that it shouldn't be so. AND, the writting as usuall is
fantastic incompetent. To illustrate, i quote:
- Xah Lee trolling on clpmisc,
"perl bug File::Basename and Perl's nature"
------------------------------
Date: 29 Jul 2004 07:35:12 -0700
From: volker.nicolai@philips.com (Volker Nicolai)
Subject: Perl debugger in Perl script hierarchy
Message-Id: <861f3588.0407290635.a265d20@posting.google.com>
Hi,
I have a huge bunch of Perl scripts which invoke each other mainly
by the system command (just have to use them, did not write the
stuff myself).
First question: Isn't there a better way to make a hierarchy of
Perl scripts than to use system("sub_script") again and again?
Second question: I tried to debug the beast :-) but the problem
is that the debug switch -d which I have set e.g. in the
first/upmost script gets "lost" as soon as the system command
executes a subscript. That in general seems sort of reasonable
to me but then how can I overcome the problem that the debugger
does not stop in this invoked sub script (I mean except setting
the -d flag in each of the 100 sub scripts which is a problem
if I do not want to use the debugger any more - tried it with
the 1st sub hierarchy, seems to work).
Third question: Logically in the top script I can not see the
subroutines of the sub scripts before I dive into them.
What can I do to tell the debugger to stop @ a certain
subroutine deep down in the hierarchy. I tried to use
$DB::single = 1 / 2 respectively and
$DB::signal = 1
but the bloody thing does not care :-\.
This is probably related to questions 2:
No debugger activation no stopping, correct?
Final question: Is there any debugger documentation
where problems like these are covered?
Thanks for any contribution.
Volker
Volker Nicolai
Philips Semiconductors
Hamburg, Germany
------------------------------
Date: Thu, 29 Jul 2004 10:47:58 -0400
From: Paul Lalli <mritty@gmail.com>
Subject: Re: Perl debugger in Perl script hierarchy
Message-Id: <20040729104312.W3404@barbara.cs.rpi.edu>
On Thu, 29 Jul 2004, Volker Nicolai wrote:
> Hi,
>
> I have a huge bunch of Perl scripts which invoke each other mainly
> by the system command (just have to use them, did not write the
> stuff myself).
>
> First question: Isn't there a better way to make a hierarchy of
> Perl scripts than to use system("sub_script") again and again?
Yes. For simplicity, try using 'do' instead of system. Read about it at
perldoc -f do
The really canonical way to do this is using modules, however. If you're
ready to get your feet wet, read some documentation on 'use', 'require',
and the host of module documentation available from perldoc.
> Second question: I tried to debug the beast :-) but the problem
> is that the debug switch -d which I have set e.g. in the
> first/upmost script gets "lost" as soon as the system command
> executes a subscript.
This will be fixed when you use 'do' instead of 'system'
> Third question: Logically in the top script I can not see the
> subroutines of the sub scripts before I dive into them.
> What can I do to tell the debugger to stop @ a certain
> subroutine deep down in the hierarchy.
use modules. :)
>I tried to use
> $DB::single = 1 / 2 respectively and
> $DB::signal = 1
> but the bloody thing does not care :-\.
> This is probably related to questions 2:
> No debugger activation no stopping, correct?
>
> Final question: Is there any debugger documentation
> where problems like these are covered?
I've not tried searching for such things.
Paul Lalli
------------------------------
Date: Thu, 29 Jul 2004 15:24:27 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Perl debugger in Perl script hierarchy
Message-Id: <LE8Oc.41199$qT3.30763@nwrddc03.gnilink.net>
Volker Nicolai wrote:
> I have a huge bunch of Perl scripts which invoke each other mainly
> by the system command (just have to use them, did not write the
> stuff myself).
Ouch, what a concept!
> First question: Isn't there a better way to make a hierarchy of
> Perl scripts than to use system("sub_script") again and again?
Absolutely. Use modules (perldoc -f use, perldoc -f require, perldoc
perlmod).
Then the problems indicated by your other questions will pretty much vanish.
jue
------------------------------
Date: Thu, 29 Jul 2004 16:27:23 GMT
From: peter@PSDT.com (Peter Scott)
Subject: Re: Perl debugger in Perl script hierarchy
Message-Id: <Lz9Oc.135806$ek5.45987@pd7tw2no>
In article <861f3588.0407290635.a265d20@posting.google.com>,
volker.nicolai@philips.com (Volker Nicolai) writes:
>Second question: I tried to debug the beast :-) but the problem
>is that the debug switch -d which I have set e.g. in the
>first/upmost script gets "lost" as soon as the system command
>executes a subscript. That in general seems sort of reasonable
>to me but then how can I overcome the problem that the debugger
>does not stop in this invoked sub script (I mean except setting
>the -d flag in each of the 100 sub scripts which is a problem
>if I do not want to use the debugger any more - tried it with
>the 1st sub hierarchy, seems to work).
Set the environment variable PERL5OPT to '-d'.
--
Peter Scott
http://www.perldebugged.com/
*** NEW *** http://www.perlmedic.com/
------------------------------
Date: Mon, 2 Aug 2004 21:20:26 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: Perl debugger in Perl script hierarchy
Message-Id: <cemb6q$2oi6$1@agate.berkeley.edu>
[A complimentary Cc of this posting was sent to
Volker Nicolai
<volker.nicolai@philips.com>], who wrote in article <861f3588.0407290635.a265d20@posting.google.com>:
> Second question: I tried to debug the beast :-) but the problem
> is that the debug switch -d which I have set e.g. in the
> first/upmost script gets "lost" as soon as the system command
> executes a subscript.
env PERL5OPTS=-d perl -S yourscript
(but make sure that you are using xterm or somesuch, so that kids are
controlled from different windows).
> Third question: Logically in the top script I can not see the
> subroutines of the sub scripts before I dive into them.
> What can I do to tell the debugger to stop @ a certain
> subroutine deep down in the hierarchy.
The debugger writes a configuration file; you may program it from this
file; in particular, force it to set breakpoints (using the whole
power of Perl, in particular, you can make it conditional on the name
of the script, etc).
All this power is there. However, as other replies indicate, these
solutions are for different problems. In your case, just use modules.
Hope this helps,
Ilya
------------------------------
Date: Mon, 26 Jul 2004 00:14:23 GMT
From: "IRR" <iotarhorho@REMOV3hotmail.com>
Subject: perl graph theory (using Graph::Directed)
Message-Id: <z1YMc.454$ZU.68@newssvr27.news.prodigy.com>
Hi all,
I'm fairly new to perl and graph theory, so hopefully this question isn't
too ignorant on both counts. I'm trying to input basically an edge list for
a graph, and get an output of the connected graphs that all of these edges
comprise. So for example:
Edge list input:
A B
A C
B A
D E
Perl script output:
A+B+C,D+E
using strongly_connected_graph (described in Graph::Base). Admittedly,
strongly_connected_graph is a black box to me -- I'm not sure if its doing a
DFS versus BFS or ?.
But what is clear is that this scales exponentially -- O(n^2.3) or so, based
on a few test sets) -- in time versus the total number of input edges. This
is fine for a few smaller edge lists that I have, but my eventual goal is to
do this for a set with ~50,000 vertices and ~2 million edges total. Based
on those test sets I mentioned, this size dataset will take ~7000 hours to
run on my current system, which obviously isn't reasonable -- and that's not
even accounting for things getting choked up in inputing that amount of data
with add_edge!
So my question is, am I approaching this problem with the right tools? Is
there another way within the Graph module to do this more efficiently?
Thanks,
I.R.
------------------------------
Date: Mon, 26 Jul 2004 14:02:43 -0000
From: gbacon@hiwaay.net (Greg Bacon)
Subject: Re: perl graph theory (using Graph::Directed)
Message-Id: <10ga3o32g4dgu22@corp.supernews.com>
In article <z1YMc.454$ZU.68@newssvr27.news.prodigy.com>,
IRR <iotarhorho@REMOV3hotmail.com> wrote:
: I'm fairly new to perl and graph theory, so hopefully this question
: isn't too ignorant on both counts. I'm trying to input basically an
: edge list for a graph, and get an output of the connected graphs that
: all of these edges comprise. [...]
Do you want connected subgraphs or strongly connected? You say
connected here, but you're searching for strongly connected subgraphs
with Graph::Base::strongly_connected_graph.
You say you're new to graph theory, so I'll give quick overviews in
case you don't know the difference. A connected graph (perhaps called
weakly connected for emphasis) is a graph such that for each vertex v,
v is reachable from some other vertex w. A strongly connected graph is
one such that for each pair of vertices v and w, there's a path from v
to w and a path from w to v.
Below is a rendering in Perl of the algorithm from Baase that
enumerates weakly connected subgraphs. The author reports time
complexity of Theta(max(n,m)) with space Theta(n+m), where n is the
number of vertices and m is the number of edges.
#! /usr/local/bin/perl
use warnings;
use strict;
# from Baase's *Computer Algorithms*, 2nd ed., pg. 180
sub dfs {
my $v = shift;
my $adj = shift;
my $mark = shift;
my $tag = shift;
$mark->{$v} = $tag;
while ($adj->{$v} && @{ $adj->{$v} }) {
my $w = shift @{ $adj->{$v} };
dfs($w,$adj,$mark,$tag) unless $mark->{$w};
}
}
sub concomps {
# destructive, so copy
my %adj = map ref($_) ? [ @$_ ] : $_, %{ shift @_ };
my @v = @_;
my %mark;
my $componentNumber = 0;
foreach my $v (@v) {
unless ($mark{$v}) {
++$componentNumber;
dfs $v, \%adj, \%mark, $componentNumber;
}
}
my %subgraph;
for (keys %mark) {
push @{ $subgraph{$mark{$_}} }, $_;
}
values %subgraph;
}
## main
my %adj;
my %v;
while (<DATA>) {
my($v,$w) = split;
# treat graph as undirected
push @{ $adj{$v} } => $w;
push @{ $adj{$w} } => $v;
++$v{$v};
++$v{$w};
}
print join("," => map join("+", sort @$_), concomps \%adj, keys %v), "\n";
__DATA__
A B
A C
B A
D E
The author used arrays, and the code above uses hashes to be more
Perlish but with time and space penalties. If the size of your input
makes you consider switching back to arrays, you might also consider
switching to a lower-level language.
Hope this helps,
Greg
--
Those who wish to preserve freedom should recognize, however, that inflation
is probably the most important single factor in that vicious circle wherein
one kind of government action makes more and more government control necessary.
-- F. A. Hayek
------------------------------
Date: Tue, 27 Jul 2004 03:08:54 GMT
From: "IRR" <iotarhorho@REMOV3hotmail.com>
Subject: Re: perl graph theory (using Graph::Directed)
Message-Id: <aHjNc.2921$AY5.2918@newssvr21.news.prodigy.com>
Thanks Greg,
You're exactly right, and I can see how strongly_connected_graph could
really eat up a substantial amount of time. That script you gave works
seamlessly and gave exactly what I was after with about 2 lines of
modification -- and it did so around 100x faster than my previous attempt!
Also picked up a copy of the book at the local library (1st edition, but it
still has an informative section on graph algorithms).
Hugely obliged,
I.R.
"Greg Bacon" <gbacon@hiwaay.net> wrote in message
news:10ga3o32g4dgu22@corp.supernews.com...
> In article <z1YMc.454$ZU.68@newssvr27.news.prodigy.com>,
> IRR <iotarhorho@REMOV3hotmail.com> wrote:
>
> : I'm fairly new to perl and graph theory, so hopefully this question
> : isn't too ignorant on both counts. I'm trying to input basically an
> : edge list for a graph, and get an output of the connected graphs that
> : all of these edges comprise. [...]
>
> Do you want connected subgraphs or strongly connected? You say
> connected here, but you're searching for strongly connected subgraphs
> with Graph::Base::strongly_connected_graph.
>
> You say you're new to graph theory, so I'll give quick overviews in
> case you don't know the difference. A connected graph (perhaps called
> weakly connected for emphasis) is a graph such that for each vertex v,
> v is reachable from some other vertex w. A strongly connected graph is
> one such that for each pair of vertices v and w, there's a path from v
> to w and a path from w to v.
>
> Below is a rendering in Perl of the algorithm from Baase that
> enumerates weakly connected subgraphs. The author reports time
> complexity of Theta(max(n,m)) with space Theta(n+m), where n is the
> number of vertices and m is the number of edges.
>
> #! /usr/local/bin/perl
>
> use warnings;
> use strict;
>
> # from Baase's *Computer Algorithms*, 2nd ed., pg. 180
>
> sub dfs {
> my $v = shift;
> my $adj = shift;
> my $mark = shift;
> my $tag = shift;
>
> $mark->{$v} = $tag;
>
> while ($adj->{$v} && @{ $adj->{$v} }) {
> my $w = shift @{ $adj->{$v} };
>
> dfs($w,$adj,$mark,$tag) unless $mark->{$w};
> }
> }
>
> sub concomps {
> # destructive, so copy
> my %adj = map ref($_) ? [ @$_ ] : $_, %{ shift @_ };
> my @v = @_;
>
> my %mark;
>
> my $componentNumber = 0;
>
> foreach my $v (@v) {
> unless ($mark{$v}) {
> ++$componentNumber;
>
> dfs $v, \%adj, \%mark, $componentNumber;
> }
> }
>
> my %subgraph;
> for (keys %mark) {
> push @{ $subgraph{$mark{$_}} }, $_;
> }
>
> values %subgraph;
> }
>
> ## main
> my %adj;
> my %v;
>
> while (<DATA>) {
> my($v,$w) = split;
>
> # treat graph as undirected
> push @{ $adj{$v} } => $w;
> push @{ $adj{$w} } => $v;
>
> ++$v{$v};
> ++$v{$w};
> }
>
> print join("," => map join("+", sort @$_), concomps \%adj, keys %v),
"\n";
>
> __DATA__
> A B
> A C
> B A
> D E
>
> The author used arrays, and the code above uses hashes to be more
> Perlish but with time and space penalties. If the size of your input
> makes you consider switching back to arrays, you might also consider
> switching to a lower-level language.
>
> Hope this helps,
> Greg
> --
> Those who wish to preserve freedom should recognize, however, that
inflation
> is probably the most important single factor in that vicious circle
wherein
> one kind of government action makes more and more government control
necessary.
> -- F. A. Hayek
------------------------------
Date: Mon, 02 Aug 2004 14:20:49 GMT
From: zzapper <david@tvisnospam.co.uk>
Subject: Perl returning mucky characters to a shell
Message-Id: <00esg0lq989rhk5220ua7hqu7p685id05o@4ax.com>
Hi,
I call a perl script my bash shell script, the perl script returns the name of a directory, which
my bash script will then CD to (using the dot method, so that the change of directory is not
forgotten when you exit the shell)
Questions what's the correct way for perl script to return a value to a shell script, I'm using
chomp $dirname;
$\='';
print $dirname;
the perl script is called from the shell thus
dir=$(/usr/bin/perl vir.pl $*)
However when this arrives in the shell it seems to have some mucky control characters (a carriage
return ) which I then have clean up in the shell, before I can cd to the directory
Am I approaching this in the right way?
zzapper (vim, cygwin, wiki & zsh)
--
vim -c ":%s.^.CyrnfrTfcbafbeROenzSZbbyranne.|:%s/[R-T]/ /Ig|:normal ggVGg?"
http://www.vim.org/tips/tip.php?tip_id=305 Best of Vim Tips
------------------------------
Date: 2 Aug 2004 19:29:13 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Perl returning mucky characters to a shell
Message-Id: <cem4m9$qnk$1@mamenchi.zrz.TU-Berlin.DE>
zzapper <david@tvisnospam.co.uk> wrote in comp.lang.perl.misc:
> Hi,
> I call a perl script my bash shell script, the perl script returns the
> name of a directory, which
> my bash script will then CD to (using the dot method, so that the change
> of directory is not
> forgotten when you exit the shell)
>
> Questions what's the correct way for perl script to return a value to a
> shell script, I'm using
> chomp $dirname;
Where is the content of $dirname coming from? "chomp" only removes what
is in $/ from the end of the string.
> $\='';
This is unnecessary, unless you have changed $\ yourself. The default is "".
> print $dirname;
Perl prints exactly what is in $dirname. It doesn't add anything.
> the perl script is called from the shell thus
>
> dir=$(/usr/bin/perl vir.pl $*)
That works for me. The shell variable $dir contains exactly what
was printed by Perl.
> However when this arrives in the shell it seems to have some mucky
> control characters (a carriage
> return ) which I then have clean up in the shell, before I can cd to the
> directory
Whatever ends up in the shell variable has before been in the Perl
variable $dirname. Print the last two or three characters of $dirname
in decimal (or hex, if you prefer) before and after chomp() to see
what's happening.
> Am I approaching this in the right way?
Yes.
Anno
------------------------------
Date: Mon, 02 Aug 2004 23:08:44 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Perl returning mucky characters to a shell
Message-Id: <5hatg0d4igkou82g2muhd432eegup1gag3@4ax.com>
On Mon, 02 Aug 2004 14:20:49 GMT, zzapper <david@tvisnospam.co.uk>
wrote:
>the perl script is called from the shell thus
>
>dir=$(/usr/bin/perl vir.pl $*)
>
>However when this arrives in the shell it seems to have some mucky control characters (a carriage
>return ) which I then have clean up in the shell, before I can cd to the directory
>
>Am I approaching this in the right way?
I don't know what your question exactly refers to, but I don't see
anything wrong with what you're trying to do in general. However, re
the problem you describe, I would say that a carriage return shouldn't
do any difference[*] and experimenting a bit shows that indeed it is
so:
# pwd
/tmp
# cd $(perl -le 'print "/var/tmp"')
# pwd
/var/tmp
[*] Since virtually all cmd line utilities do end their output with
one and yet we successfully use $() or backticks on *that* output.
Michele
--
#!/usr/bin/perl -lp
BEGIN{*ARGV=do{open $_,q,<,,\$/;$_}}s z^z seek DATA,11,$[;($,
=ucfirst<DATA>)=~s x .*x q^~ZEX69l^^q,^2$;][@,xe.$, zex,s e1e
q 1~BEER XX1^q~4761rA67thb ~eex ,s aba m,P..,,substr$&,$.,age
__END__
------------------------------
Date: Tue, 03 Aug 2004 02:35:58 GMT
From: zzapper <david@tvisnospam.co.uk>
Subject: Re: Perl returning mucky characters to a shell
Message-Id: <mgqtg0pncr9qg56iq37raoi9m766sm5nv6@4ax.com>
On Mon, 02 Aug 2004 23:08:44 +0200, wrote:
>On Mon, 02 Aug 2004 14:20:49 GMT, zzapper <david@tvisnospam.co.uk>
>wrote:
>
>>the perl script is called from the shell thus
>>
>>dir=$(/usr/bin/perl vir.pl $*)
>>
>>However when this arrives in the shell it seems to have some mucky control characters (a carriage
>>return ) which I then have clean up in the shell, before I can cd to the directory
>>
>>Am I approaching this in the right way?
>
>I don't know what your question exactly refers to, but I don't see
>anything wrong with what you're trying to do in general. However, re
>the problem you describe, I would say that a carriage return shouldn't
>do any difference[*] and experimenting a bit shows that indeed it is
>so:
>
> # pwd
> /tmp
> # cd $(perl -le 'print "/var/tmp"')
> # pwd
> /var/tmp
>
>
>[*] Since virtually all cmd line utilities do end their output with
>one and yet we successfully use $() or backticks on *that* output.
>
>
>Michele
Thanx for various replies, I believe it's a bit of a Cygwin oddity, where an unwanted Carriage
Return is being appended to perl-print-returned value, whatever it is the shell sees it as a ^M,
it's no problem to filter it in the shell. (zsh)
zzapper (vim, cygwin, wiki & zsh)
--
vim -c ":%s.^.CyrnfrTfcbafbeROenzSZbbyranne.|:%s/[R-T]/ /Ig|:normal ggVGg?"
http://www.vim.org/tips/tip.php?tip_id=305 Best of Vim Tips
------------------------------
Date: Tue, 03 Aug 2004 14:56:40 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Perl returning mucky characters to a shell
Message-Id: <lakug0d5uiset00ic07sspb7d3ib1bfet8@4ax.com>
On Tue, 03 Aug 2004 02:35:58 GMT, zzapper <david@tvisnospam.co.uk>
wrote:
>Thanx for various replies, I believe it's a bit of a Cygwin oddity, where an unwanted Carriage
>Return is being appended to perl-print-returned value, whatever it is the shell sees it as a ^M,
>it's no problem to filter it in the shell. (zsh)
Indeed this must be a Cygwin oddity, since ^M indeed is a carriage
return (\r):
perl -le 'print for map ord, split //, "\n\f\cM"'
Of course this has to do with the different representations of
line-endings in DOS and UNIX respectively. So what happens is that
perl is producing output with correct line-endings for your OS
(Win32), whereas the shell reasonably expects UNIX line-endings and of
the couple \r\n, it removes \n and considers \r to be part of the
filename.
By any chance, are you using AS Perl? I have no experience with
Cygwin, but I think that under that environment you'd better use
Cygwin's perl instead, anyway.
As a correcting measure you may try binmode()ing stdout though.
Briefly tested here and seems to work:
C:\TEMP>perl -le "print ''" | cat -A
^M$
C:\TEMP>perl -le "binmode STDOUT; print ''" | cat -A
$
HTH,
Michele
--
you'll see that it shouldn't be so. AND, the writting as usuall is
fantastic incompetent. To illustrate, i quote:
- Xah Lee trolling on clpmisc,
"perl bug File::Basename and Perl's nature"
------------------------------
Date: Wed, 28 Jul 2004 07:53:47 -0700
From: "Sam Matheson" <samm@chepnt.net>
Subject: perl script to manage internal address mailing lists
Message-Id: <aPWdnfCeXMJhIJrcRVn-vw@giganews.com>
Our company has about 1,700 people, and all of them are on various mail
lists like accounting, management, corporate, maintenance, branch office,
etc. Most people are on three or more lists. Right now we build out each
list in pick basic, which has a number of drawbacks. What I would like to do
is just have the database spit out a list of email addresses and
departments, and have perl just parse the list and build an email list for
each division/department, and then store it where postfix can loop through
it when an email is sent to a list. When I search google for this type of
functionality, all I get are mailing list managers like mailman, whi is not
what we want. Is there a pre-written solution for this, or must I start from
scratch? We are a big company and we would be willing to pay for a
commercial solution.
TIA,
Sam
------------------------------
Date: Wed, 28 Jul 2004 13:19:29 -0400
From: thundergnat <thundergnat@hotmail.com>
Subject: Re: perl script to manage internal address mailing lists
Message-Id: <4107e016$0$2833$61fed72c@news.rcn.com>
Sam Matheson wrote:
> Our company has about 1,700 people, and all of them are on various mail
> lists like accounting, management, corporate, maintenance, branch office,
> etc. Most people are on three or more lists. Right now we build out each
> list in pick basic, which has a number of drawbacks. What I would like to do
> is just have the database spit out a list of email addresses and
> departments, and have perl just parse the list and build an email list for
> each division/department, and then store it where postfix can loop through
> it when an email is sent to a list. When I search google for this type of
> functionality, all I get are mailing list managers like mailman, whi is not
> what we want. Is there a pre-written solution for this, or must I start from
> scratch? We are a big company and we would be willing to pay for a
> commercial solution.
>
> TIA,
> Sam
>
>
I don't know of any commercial scripts offhand to do this but really,
what you are asking for sounds relatively easy to do.
Import the addresses / list memberships into a hash of hashes then print
out the addresses in each list based on the existence of list membership.
If you are trying to do it youself, post some code and we'll try to help
you with it, otherwise, you may have better luck posting in a newsgroup
that has "jobs" somewhere in the title.
Good Luck.
------------------------------
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 6817
***************************************