[22322] in Perl-Users-Digest
Perl-Users Digest, Issue: 4543 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Feb 10 19:17:08 2003
Date: Mon, 10 Feb 2003 16:11:44 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 10 Feb 2003 Volume: 10 Number: 4543
Today's topics:
Test if directory is accessable, other Q's <cjdugan<-->@lucent.com>
Re: Test if directory is accessable, other Q's <krahnj@acm.org>
Re: Test if directory is accessable, other Q's (David Efflandt)
Re: Test if directory is accessable, other Q's <Juha.Laiho@iki.fi>
Re: Test if directory is accessable, other Q's <barryk2@SPAM-KILLER.mts.net>
Re: Test if directory is accessable, other Q's <mgjv@tradingpost.com.au>
Re: Test if directory is accessable, other Q's <cjdugan@lucent.com>
trying to convert a boolean query into xml (nayeem)
Re: trying to convert a boolean query into xml <nobull@mail.com>
Two annoying Perl syntax issues (ixtahdoom)
Re: Two annoying Perl syntax issues <pinyaj@rpi.edu>
Re: Two annoying Perl syntax issues <skuo@mtwhitney.nsc.com>
Re: Two annoying Perl syntax issues (Malcolm Dew-Jones)
unix copy command? <dbruno@ucla.edu>
Re: unix copy command? <xyf@nixnotes.org>
Re: unix copy command? <w_ichmann@uni-wuppertal.de>
Re: unix copy command? <me@privacy.net>
Re: unix copy command? <bart.lateur@pandora.be>
Re: unix copy command? <GPatnude@adelphia.net>
Using $^N in Regular Expressions (Hemuda)
Re: Using $^N in Regular Expressions <goldbb2@earthlink.net>
Re: Using $^N in Regular Expressions (Jay Tilton)
Re: Using $^N in Regular Expressions (Hemuda)
Re: Using $^N in Regular Expressions <bigj@kamelfreund.de>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 07 Feb 2003 19:25:35 GMT
From: Kris Dugan <cjdugan<-->@lucent.com>
Subject: Test if directory is accessable, other Q's
Message-Id: <1109_1044645935@nntp.lucent.com>
Greetings,
Q1:
--------------------------------------------------------
I am trying to write a program that will read a file. In
looking at the Learning Perl book, I see options for -e (if
file/dir exists).
But, I may have the strange case where the directory exists,
but is not accessable by my program. Is there a way to test
for this case?
machine> cd AP1_ROP
/bin/ksh: AP1_ROP: permission denied
--------------------------------------------------------
Q2:
I have a report that has a format (using FileHandle,
and the methods format_name and format_top_name).
During this report, I no longer want to use the TOP
format. Is there a way to "undefine" the top
format? I have tried the following:
undef format_top_name;
and
format_top_name SUM_LOG "";
These don't seem to work, as I get the following error
message:
Undefined top format "main::" called at trkrptomp line 763
(The undef method will coredump)
Suggestions?
-------------------------------------------------------
Q3:
I am trying to perform a pattern match on a string, to
see if it has a character that occurs X amount of times.
For example, I could have the string a_b_c_d, and
bdkj_io_yijk. In my pattern test, I want to know how
many times the "_" occurs within a string.
So far, I have the pattern:
/.*_.*_.*_.*/
But I was wondering if there were a more elegant solution than
this.
-------------------------------------------------------
Thanks,
Kris Dugan
------------------------------
Date: Fri, 07 Feb 2003 20:15:16 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Test if directory is accessable, other Q's
Message-Id: <3E4413B2.E5641303@acm.org>
"Kris Dugan
>
> Q1:
> --------------------------------------------------------
> I am trying to write a program that will read a file. In
> looking at the Learning Perl book, I see options for -e (if
> file/dir exists).
>
> But, I may have the strange case where the directory exists,
> but is not accessable by my program. Is there a way to test
> for this case?
It could be that you are not the owner or in the group that owns it. It
could be that you don't have read or write permission for it. Use the
file test operators to find out.
perldoc -f -o
perldoc -f -r
perldoc -f -w
perldoc -f -x
> Q3:
> I am trying to perform a pattern match on a string, to
> see if it has a character that occurs X amount of times.
> For example, I could have the string a_b_c_d, and
> bdkj_io_yijk. In my pattern test, I want to know how
> many times the "_" occurs within a string.
>
> So far, I have the pattern:
> /.*_.*_.*_.*/
>
> But I was wondering if there were a more elegant solution than
> this.
my $underscore_count = $string =~ tr/_//;
John
--
use Perl;
program
fulfillment
------------------------------
Date: Sat, 8 Feb 2003 01:49:24 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: Test if directory is accessable, other Q's
Message-Id: <slrnb48oh3.8vg.efflandt@typhoon.xnet.com>
On Fri, 07 Feb 2003 20:15:16 GMT, John W. Krahn <krahnj@acm.org> wrote:
> "Kris Dugan
>>
>> Q1:
>> --------------------------------------------------------
>> I am trying to write a program that will read a file. In
>> looking at the Learning Perl book, I see options for -e (if
>> file/dir exists).
>>
>> But, I may have the strange case where the directory exists,
>> but is not accessable by my program. Is there a way to test
>> for this case?
>
> It could be that you are not the owner or in the group that owns it. It
> could be that you don't have read or write permission for it. Use the
> file test operators to find out.
>
> perldoc -f -o
> perldoc -f -r
> perldoc -f -w
> perldoc -f -x
Note that to access a dir you need x permission (and proper file
permission).
To readdir (dir listing), you need r & x permission.
--
David Efflandt - All spam ignored http://www.de-srv.com/
http://www.autox.chicago.il.us/ http://www.berniesfloral.net/
http://cgi-help.virtualave.net/ http://hammer.prohosting.com/~cgi-wiz/
------------------------------
Date: Sat, 08 Feb 2003 08:52:00 GMT
From: Juha Laiho <Juha.Laiho@iki.fi>
Subject: Re: Test if directory is accessable, other Q's
Message-Id: <b22gd9$97m$2@ichaos.ichaos-int>
Kris Dugan <cjdugan<-->@lucent.com> said:
>I am trying to write a program that will read a file. In
>looking at the Learning Perl book, I see options for -e (if
>file/dir exists).
>
>But, I may have the strange case where the directory exists,
>but is not accessable by my program. Is there a way to test
>for this case?
Just try opening the file you're going to read. A status value
will be returned; just check that. Then, if you wish, you can
start backtracking as to which part of the directory path it
was where you were not allowed the required access -- but as
a simple case, attempt open(), and see if it fails.
Testing for accessibility before doing the open will leave a race
condition; the test may say that you have access, but the open() can
still fail, as there is a possibility that the permissions are changed
(by another thread/process) between the test and open() - so you'll need
to check the return status from open() anyway (which makes it so that
there's very little reason to do the separate access check anyway).
>I am trying to perform a pattern match on a string, to
>see if it has a character that occurs X amount of times.
>For example, I could have the string a_b_c_d, and
>bdkj_io_yijk. In my pattern test, I want to know how
>many times the "_" occurs within a string.
I don't see a direct way to do this wirh regexes, but am thinking
of two solutions I might use myself:
- make a temporary copy of the string
- from the copy, remove characters other than _
($temp = $orig) =~ s/[^_]+//g;
- calculate length of the remaining string
$res = length($temp);
- split the string into temporary array
$num_flds = split(/_/,$orig);
$res = $num_flds+1;
The latter might be useful for the later processing of the original
string, too; the results of the split are left in the @_ array.
--
Wolf a.k.a. Juha Laiho Espoo, Finland
(GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
"...cancel my subscription to the resurrection!" (Jim Morrison)
------------------------------
Date: Sat, 8 Feb 2003 08:33:26 -0600
From: Barry Kimelman <barryk2@SPAM-KILLER.mts.net>
Subject: Re: Test if directory is accessable, other Q's
Message-Id: <MPG.18aed133aa0d75129896ef@news.mts.net>
In article <1109_1044645935@nntp.lucent.com>, Kris Dugan <cjdugan<--
>@lucent.com> (Kris Dugan <cjdugan<-->@lucent.com>) says...
> Greetings,
>
> Q1:
> --------------------------------------------------------
> I am trying to write a program that will read a file. In
> looking at the Learning Perl book, I see options for -e (if
> file/dir exists).
>
> But, I may have the strange case where the directory exists,
> but is not accessable by my program. Is there a way to test
> for this case?
>
> machine> cd AP1_ROP
> /bin/ksh: AP1_ROP: permission denied
if ( -x $dirname ) {
### do something
}
else {
print "I have no access to directory $dirname\n";
}
> --------------------------------------------------------
>
> Q2:
> I have a report that has a format (using FileHandle,
> and the methods format_name and format_top_name).
> During this report, I no longer want to use the TOP
> format. Is there a way to "undefine" the top
> format? I have tried the following:
>
> undef format_top_name;
> and
> format_top_name SUM_LOG "";
>
> These don't seem to work, as I get the following error
> message:
> Undefined top format "main::" called at trkrptomp line 763
> (The undef method will coredump)
>
> Suggestions?
> -------------------------------------------------------
>
> Q3:
> I am trying to perform a pattern match on a string, to
> see if it has a character that occurs X amount of times.
> For example, I could have the string a_b_c_d, and
> bdkj_io_yijk. In my pattern test, I want to know how
> many times the "_" occurs within a string.
>
> So far, I have the pattern:
> /.*_.*_.*_.*/
>
> But I was wondering if there were a more elegant solution than
> this.
> -------------------------------------------------------
>
> Thanks,
--
---------
Barry Kimelman
Winnipeg, Manitoba, Canada
email : bkimelman@hotmail.com
------------------------------
Date: Mon, 10 Feb 2003 04:29:44 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Test if directory is accessable, other Q's
Message-Id: <slrnb4ealo.se5.mgjv@verbruggen.comdyn.com.au>
On Fri, 07 Feb 2003 19:25:35 GMT,
Kris Dugan <> wrote:
> Greetings,
>
> Q1:
> --------------------------------------------------------
> I am trying to write a program that will read a file. In
> looking at the Learning Perl book, I see options for -e (if
> file/dir exists).
>
> But, I may have the strange case where the directory exists,
> but is not accessable by my program. Is there a way to test
> for this case?
>
> machine> cd AP1_ROP
> /bin/ksh: AP1_ROP: permission denied
Since you seem to be on Unix, the direct answer would be to use -x on
the directory. Whether that is the answer to your problem depends a
little bit on what your problem really is. If you intend to read that
directory, you also need read permission (-r). If you just need to
access a file somewhere down in the hierarchy, you should probably
just try to access the file, and see what happens.
> Q2:
> I have a report that has a format (using FileHandle,
> and the methods format_name and format_top_name).
> During this report, I no longer want to use the TOP
> format. Is there a way to "undefine" the top
> format? I have tried the following:
Why do you think you want to undefine it?
> undef format_top_name;
> and
> format_top_name SUM_LOG "";
>
> These don't seem to work, as I get the following error
> message:
> Undefined top format "main::" called at trkrptomp line 763
> (The undef method will coredump)
Hmm.. That's an interesting message. I get something very different,
$ cat /tmp/foo.pl
#!/usr/local/bin/perl -w
format GROO =
@<<<
$_
.
open GROO, ">&STDOUT";
$_ = "groo";
write(GROO);
undef GROO
$ /opt/perl/bin/perl5.00503 /tmp/foo.pl
Can't modify constant item in undef operator at /tmp/foo.pl line 13,
near "GROO;"
Execution of /tmp/foo.pl aborted due to compilation errors
$ /opt/perl/bin/perl5.6.1 /tmp/foo.pl
groo
Modification of a read-only value attempted at /tmp/foo.pl line 13.
Attempt to free unreferenced scalar.
Attempt to free unreferenced scalar.
zsh: segmentation fault /opt/perl/bin/perl5.6.1 /tmp/foo.pl
(looks like a bug in 5.6)
$ /opt/perl-5.8.0/bin/perl5.8.0 /tmp/foo.pl
Can't modify constant item in undef operator at /tmp/foo.pl line 13,
near "GROO;"
Execution of /tmp/foo.pl aborted due to compilation errors.
Looks like an error here, but with a totally different message from
yours. And with strict on, I get more/different errors.
I wouldn't know of a way of "undefining" a format, and I can't really
think of a reason to do it either. maybe some messing around with the
symbol table would work, but I can't even come up with a reason why I
would want to investigate that either :)
Where is the code that generates your error message (please, no more
than a few lines)
> Q3:
> I am trying to perform a pattern match on a string, to
> see if it has a character that occurs X amount of times.
The question above could be read in several ways (ignoring the fact
that you already seem to have made up your mind about the pattern
matching, which most likely is wrong):
- I want to find how often a given character appears in a string
- I want to know which characters appears a given number of times
in a string
- I want to know whether a given character appears a given number
of times in a string
I'm assuming you mean the first. The third follows trivially from the
solution to the first. The second one is harder.
The canonical way is to use tr to count characters.
my $count = $string =~ tr/_/_/;
It is possible to do it with a regex match:
$count = () = $str =~ /_/g;
but I see no reason to do that. You could use index (or rindex):
my $pos = -1;
my $count = 0;
$count++ while ($pos = index $str, "_", $pos + 1) >= 0;
but again, I see no reason to do that.
Ok, let's have a look at the second possible interpretation of the
question:
- I want to know which characters appears a given number of times
in a string
One solution:
my (%char_count, %count_char);
# Count individual characters
$char_count{$1}++ while $str =~ /(.)/g;
# pivot the hash
push @{$count_char{$char_count{$_}}}, $_ for keys %char_count;
Now $count_char{$number} contains an array reference with all the
characters occurring $number times in $str. Of course, if you only
need the ones that occur $number times, you can also simply do:
my $number = 3;
my @n_times;
for (keys %char_count)
{
push @n_times, $_ if $char_count{$_} == $number;
}
after which @n_times contains the characters that appeared $number
times in the string.
For the next time you post, please try to be as exact and accurate as
you can, especially when reporting errors. Copy and paste. Also,
please don't post more than one question at the time. It'll make the
thread neater, and since these threads are archived on
groups.google.com, and are a valuable source of information for
people, it's better if they are neater.
Martien
--
|
Martien Verbruggen |
Trading Post Australia | What's another word for Thesaurus?
|
------------------------------
Date: Mon, 10 Feb 2003 16:13:45 -0600
From: Kris Dugan <cjdugan@lucent.com>
Subject: Re: Test if directory is accessable, other Q's
Message-Id: <3E482419.C9647C43@lucent.com>
Code snippet (lines 721 - 755):
if ($aopt)
{
#print the next section
format_top_name SUM_LOG "SUM_TRK_INV_HDR";
format_name SUM_LOG "SUM_TRK_INV_HDR";
#If there aren't many lines left in the
summary file,
# don't print the section header. It will be
printed
# on the next page.
if ($- < 8)
{
$- = 0; #Force a page break
}
else
{
write;
}
format_name SUM_LOG "SUM_TRK_INV";
foreach $key (keys %invtrk_sum)
{
$fails = $invtrk_sum{$key};
($dcs, $trkgrp, $trkmem, $fmsg) =
split(/_/, $key);
$dcs_tot[$dcs] += $fails;
write;
}
}
#format_top_name SUM_LOG "";
#Remove the format top.
$^ = 0;
format_name SUM_LOG "SUM_DCS_HDR";
write;
format_name SUM_LOG "SUM_DCS";
.....
Basically, what I'm doing is I'm using the $FORMAT_TOP_NAME as
both the page header and also a section header. In the code
above, I use format_name as the section header, then change
formats for the data to follow the section header. This
is supposed to be a summary file, which is short and concise;
rather than a multipage report.
Current error:
Undefined top format "0" called at trkrptomp line 810.
Using format_top_name SUM_LOG "";:
Undefined top format "main::" called at trkrptomp line 811.
Using undef format_top_name;:
Name "main::format_top_name" used only once: possible typo at
trkrptomp line 753.
Segmentation Fault(coredump)
your code doesn't reference the scalar variable
$FORMAT_TOP_NAME or $^, instead you're passing a filehandle.
>
> > Q2:
> > I have a report that has a format (using FileHandle,
> > and the methods format_name and format_top_name).
> > During this report, I no longer want to use the TOP
> > format. Is there a way to "undefine" the top
> > format? I have tried the following:
>
> Why do you think you want to undefine it?
>
> > undef format_top_name;
> > and
> > format_top_name SUM_LOG "";
> >
> > These don't seem to work, as I get the following error
> > message:
> > Undefined top format "main::" called at trkrptomp line 763
> > (The undef method will coredump)
>
> Hmm.. That's an interesting message. I get something very
different,
>
> $ cat /tmp/foo.pl
> #!/usr/local/bin/perl -w
>
> format GROO =
> @<<<
> $_
> ..
>
> open GROO, ">&STDOUT";
> $_ = "groo";
> write(GROO);
>
> undef GROO
>
> $ /opt/perl/bin/perl5.00503 /tmp/foo.pl
> Can't modify constant item in undef operator at /tmp/foo.pl
line 13,
> near "GROO;"
> Execution of /tmp/foo.pl aborted due to compilation errors
>
> $ /opt/perl/bin/perl5.6.1 /tmp/foo.pl
> groo
> Modification of a read-only value attempted at /tmp/foo.pl
line 13.
> Attempt to free unreferenced scalar.
> Attempt to free unreferenced scalar.
> zsh: segmentation fault /opt/perl/bin/perl5.6.1 /tmp/foo.pl
>
> (looks like a bug in 5.6)
>
> $ /opt/perl-5.8.0/bin/perl5.8.0 /tmp/foo.pl
> Can't modify constant item in undef operator at /tmp/foo.pl
line 13,
> near "GROO;"
> Execution of /tmp/foo.pl aborted due to compilation errors.
>
> Looks like an error here, but with a totally different
message from
> yours. And with strict on, I get more/different errors.
>
>
> I wouldn't know of a way of "undefining" a format, and I
can't really
> think of a reason to do it either. maybe some messing around
with the
> symbol table would work, but I can't even come up with a
reason why I
> would want to investigate that either :)
>
>
> Where is the code that generates your error message (please,
no more
> than a few lines)
>
------------------------------
Date: 7 Feb 2003 09:25:10 -0800
From: nayeem@ntlworld.com (nayeem)
Subject: trying to convert a boolean query into xml
Message-Id: <50e1bf38.0302070925.b64a53e@posting.google.com>
hi there
this post might have been more suitable for a algorithm group but i
couldnt find any so apologies in case its not a very appropriate post
for this group.
i am trying to convert a string such as the ones below
(a AND b) OR c
a OR (b AND c)
a AND (b OR c)
etc into XML. and the format of the XML has a lot of constraints, eg
there is a certain way to represent a first level OR, another way for
a first level AND etc.
so i was thinking if i can find a way to convert the above statement
into a btree structure then that would solve most of the problems
since its quite easy to traverse a btree and get an XML out of it.
does anyone know of a way i can convert the above to btrees such as
below
OR
/ \
AND c
/ \
a b
etc. obviously this would leave option for more complex sentences with
more brackets and layers into them.
any help would be greatly appreciated.
thanks in advance.
nayeem
------------------------------
Date: 07 Feb 2003 17:31:10 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: trying to convert a boolean query into xml
Message-Id: <u9of5ouhep.fsf@wcl-l.bham.ac.uk>
nayeem@ntlworld.com (nayeem) writes:
> this post might have been more suitable for a algorithm group but i
> couldnt find any so apologies in case its not a very appropriate post
> for this group.
Err...
> i am trying to convert a string such as the ones below
> (a AND b) OR c
> a OR (b AND c)
> a AND (b OR c)
> etc into XML. and the format of the XML has a lot of constraints, eg
> there is a certain way to represent a first level OR, another way for
> a first level AND etc.
> so i was thinking if i can find a way to convert the above statement
> into a btree structure then that would solve most of the problems
> since its quite easy to traverse a btree and get an XML out of it.
>
> does anyone know of a way i can convert the above to btrees such as
> below
> OR
> / \
> AND c
> / \
> a b
B-trees? Where does 'B' come into this? Looks like a simple
parse-tree to me.
The most popular agorithms are LALR(1) and recursive descent. I think
you'll find modules for these on CPAN.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 10 Feb 2003 10:07:27 -0800
From: ixtahdoom@yahoo.com (ixtahdoom)
Subject: Two annoying Perl syntax issues
Message-Id: <2aa9aa08.0302101007.43ca2924@posting.google.com>
Hi,
Here are two things that bug me about Perl, and I bet there is an easy
solution to both of them. They both are related to the fact that I
would like to do an operation in ONE line, rather than TWO. Nitpicky?
Yes. I slimmed down the crux of the issues:
1st.
I have a file in $temp = "/etc/stuff/foo.gz";
I want to make a path called "/etc/stuff", but this always takes me
two steps:
my $path = $temp;
$path =~ s/\/[^\/]*$//;
Is there a way to do this in ONE line? I tried join(pop(split..., but
Perl didn't like that.
2nd.
Let's say I use a back-ticked fork, and want to remove the
whitespace...
my $data = `gzgrep -c 'stuff' $file`;
$data = chomp $data;
Again, how can I do this chomp during the assignment?
Tanx!
------------------------------
Date: Mon, 10 Feb 2003 13:10:08 -0500
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
To: ixtahdoom <ixtahdoom@yahoo.com>
Subject: Re: Two annoying Perl syntax issues
Message-Id: <Pine.SGI.3.96.1030210130909.21688A-100000@vcmr-64.server.rpi.edu>
[posted & mailed]
On 10 Feb 2003, ixtahdoom wrote:
> my $path = $temp;
> $path =~ s/\/[^\/]*$//;
(my $path = $temp) =~ s!/[^/]*$!!;
> my $data = `gzgrep -c 'stuff' $file`;
> $data = chomp $data;
You DON'T want to assign the return value of chomp() to $data.
chomp(my $data = `...`);
--
Jeff Pinyan RPI Acacia Brother #734 2003 Rush Chairman
"And I vos head of Gestapo for ten | Michael Palin (as Heinrich Bimmler)
years. Ah! Five years! Nein! No! | in: The North Minehead Bye-Election
Oh. Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)
------------------------------
Date: Mon, 10 Feb 2003 11:08:49 -0800
From: Steven Kuo <skuo@mtwhitney.nsc.com>
Subject: Re: Two annoying Perl syntax issues
Message-Id: <Pine.GSO.4.21.0302101105460.15392-100000@mtwhitney.nsc.com>
On 10 Feb 2003, ixtahdoom wrote:
> Hi,
>
> Here are two things that bug me about Perl, and I bet there is an easy
> solution to both of them. They both are related to the fact that I
> would like to do an operation in ONE line, rather than TWO. Nitpicky?
> Yes. I slimmed down the crux of the issues:
>
> 1st.
> I have a file in $temp = "/etc/stuff/foo.gz";
>
> I want to make a path called "/etc/stuff", but this always takes me
> two steps:
>
> my $path = $temp;
> $path =~ s/\/[^\/]*$//;
>
> Is there a way to do this in ONE line? I tried join(pop(split..., but
> Perl didn't like that.
Try using dirname (from File::Basename):
use File::Basename;
$path = dirname($temp); # one line
>
> 2nd.
>
> Let's say I use a back-ticked fork, and want to remove the
> whitespace...
>
> my $data = `gzgrep -c 'stuff' $file`;
> $data = chomp $data;
>
> Again, how can I do this chomp during the assignment?
>
Whitespace? I presume you mean the trailing $/ character.
Use chomp and the back-tick assignment all on one line:
chomp (my $foo = `echo foo`); # remove trailing $/
print "${foo}bar\n";
--
Hope this helps,
Steven
------------------------------
Date: 10 Feb 2003 12:29:04 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: Two annoying Perl syntax issues
Message-Id: <3e480b90@news.victoria.tc.ca>
ixtahdoom (ixtahdoom@yahoo.com) wrote:
: Hi,
: Here are two things that bug me about Perl, and I bet there is an easy
: solution to both of them. They both are related to the fact that I
: would like to do an operation in ONE line, rather than TWO. Nitpicky?
: Yes. I slimmed down the crux of the issues:
: my $path = $temp;
: $path =~ s/\/[^\/]*$//;
(my $path = $temp) =~ s/\/[^\/]*$//;
: my $data = `gzgrep -c 'stuff' $file`;
: $data = chomp $data;
chomp(my $data = `gzgrep -c 'stuff' $file`);
For chomp you should really have read the docs. There's no better way to
avoid bugs and learn new stuff about old functions. (That's new to your
knowledge, not necessarily new to the function's capabilities.)
------------------------------
Date: Sun, 9 Feb 2003 22:47:17 -0800
From: "David Bruno" <dbruno@ucla.edu>
Subject: unix copy command?
Message-Id: <b27hu1$ctm$1@zinnia.noc.ucla.edu>
Hi,
I'm trying to have a perl script copy a file from one directory
to another.
I tried "cp (/file directory/file, /destination directory)
and that didn't work. The error seems to be that the "cp"
command is not being recognized.
any help would be appreciated.
thanks,
David
------------------------------
Date: Mon, 10 Feb 2003 06:57:17 GMT
From: ktb <xyf@nixnotes.org>
Subject: Re: unix copy command?
Message-Id: <slrnb4eja0.8vr.xyf@scab.nixnotes.org>
In article <b27hu1$ctm$1@zinnia.noc.ucla.edu>, David Bruno wrote:
> Hi,
>
> I'm trying to have a perl script copy a file from one directory
> to another.
> I tried "cp (/file directory/file, /destination directory)
> and that didn't work. The error seems to be that the "cp"
> command is not being recognized.
>
> any help would be appreciated.
You could call it from your perl script like -
system("cp /file directory/file /destination/directory/");
or
exec("cp /file directory/file /destination/directory/");
See:
perldoc -f exec
and
perldoc -f system
kent
--
To know the truth is to distort the Universe.
Alfred N. Whitehead (adaptation)
------------------------------
Date: Mon, 10 Feb 2003 09:28:42 +0100
From: Ingo Wichmann <w_ichmann@uni-wuppertal.de>
Subject: Re: unix copy command?
Message-Id: <b27o46$442$04$2@news.t-online.com>
David Bruno schrieb:
> I'm trying to have a perl script copy a file from one directory
> to another.
> I tried "cp (/file directory/file, /destination directory)
> and that didn't work. The error seems to be that the "cp"
> command is not being recognized.
http://www.perldoc.com/perl5.6/lib/File/Copy.html
Ingo
--
Meine Mail-Adresse enthält keinen Unterstrich
------------------------------
Date: Mon, 10 Feb 2003 23:49:38 +1100
From: "Tintin" <me@privacy.net>
Subject: Re: unix copy command?
Message-Id: <b28750$18t3ro$1@ID-172104.news.dfncis.de>
"David Bruno" <dbruno@ucla.edu> wrote in message
news:b27hu1$ctm$1@zinnia.noc.ucla.edu...
> Hi,
>
> I'm trying to have a perl script copy a file from one directory
> to another.
> I tried "cp (/file directory/file, /destination directory)
> and that didn't work. The error seems to be that the "cp"
> command is not being recognized.
No need to use non-portable commands.
use File::Copy;
copy("file1","file2") or die "copy failed $!\n";
------------------------------
Date: Mon, 10 Feb 2003 12:54:06 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: unix copy command?
Message-Id: <868f4vsg4a6d6d29485dsf310q5sl1887f@4ax.com>
David Bruno wrote:
>I'm trying to have a perl script copy a file from one directory
>to another.
Use the module File::Copy. That way, "cp" and "copy" will look and
behave like ordinary Perl keywords. (As will "mv" and "move".)
--
Bart.
------------------------------
Date: Mon, 10 Feb 2003 16:25:16 GMT
From: "codeWarrior" <GPatnude@adelphia.net>
Subject: Re: unix copy command?
Message-Id: <MnQ1a.5209$jR3.2786000@news1.news.adelphia.net>
"David Bruno" <dbruno@ucla.edu> wrote in message
news:b27hu1$ctm$1@zinnia.noc.ucla.edu...
> Hi,
>
> I'm trying to have a perl script copy a file from one directory
> to another.
> I tried "cp (/file directory/file, /destination directory)
> and that didn't work. The error seems to be that the "cp"
> command is not being recognized.
>
> any help would be appreciated.
> thanks,
> David
>
>
>
>
use File::Copy;
$SOURCEFILE = "../usr/file1.doc";
$DESTFILE = "../../file2.doc"
$result = copy($SOURCEFILE, $DESTFILE);
------------------------------
Date: 7 Feb 2003 11:12:48 -0800
From: hemuda@yahoogroups.com (Hemuda)
Subject: Using $^N in Regular Expressions
Message-Id: <20d93d09.0302071112.e422a63@posting.google.com>
Hello Gurus,
My question is regarding the usage of $^N. It does not seem to work as
expected. I have read the regex man page but it doesen't help
$_ has a string which had s as the start of my regex and e as the end of my
regex. The regex is trying to capture all
chars matching \w and seperated by , (between the start s and ending e) in
@list. Please see my session in the debugger at the bottom.
My question is why $^N is not working? (And why is it printing some
messages.)
Thanks a lot,
Hemant
----------------------------------------------------------------------------
-------------------------------------
DB<1> $_ = 'l,m sa,b,c,de x,y,z sl,m,n,o,pe %s% s0,1,2,3,4,5,6e %e% h,i'
DB<2> use Data::Dumper
DB<3> m/s(?:(\w),(?{ local @m = (@m, $^N); }))+(\w)e(?{ @list =@m})/
via UNIVERSAL: VERSION
via UNIVERSAL: can
via UNIVERSAL: isa
DB<4> p Dumper ( \@list)
$VAR1 = [
undef,
undef,
undef
];
DB<5> m/s(?:(\w),(?{ local @m = (@m, $1); }))+(\w)e(?{ @list =@m})/
via UNIVERSAL: VERSION
via UNIVERSAL: can
via UNIVERSAL: isa
DB<6> p Dumper ( \@list)
$VAR1 = [
'a',
'b',
'c'
];
------------------------------
Date: Fri, 07 Feb 2003 15:18:40 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Using $^N in Regular Expressions
Message-Id: <3E4414A0.4D95A120@earthlink.net>
Hemuda wrote:
>
> Hello Gurus,
>
> My question is regarding the usage of $^N. It does not seem to work as
> expected. I have read the regex man page but it doesen't help
I don't see any $^N in either of perldoc perlre, nor in perldoc perlvar.
I do see a $^R variable in both, but no $^N.
What is this variable, and what do you expect it to do?
--
"So, who beat the clueless idiot today?"
"Well, we flipped for it, but when Kuno
landed, he wasn't in any shape to fight."
"Next time, try flipping a *coin.*"
------------------------------
Date: Fri, 07 Feb 2003 23:26:43 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Using $^N in Regular Expressions
Message-Id: <3e443fef.147776370@news.erols.com>
hemuda@yahoogroups.com (Hemuda) wrote:
: Hello Gurus,
:
: My question is regarding the usage of $^N. It does not seem to work as
: expected. I have read the regex man page but it doesen't help
$^N was introduced with Perl 5.8. Does your man page match your Perl?
: Please see my session in the debugger at the bottom.
How about posting code instead of debugger output?
------------------------------
Date: 7 Feb 2003 17:02:35 -0800
From: hemuda@yahoogroups.com (Hemuda)
Subject: Re: Using $^N in Regular Expressions
Message-Id: <20d93d09.0302071702.457e9919@posting.google.com>
OOps!! $^N seems to be a new variable in 5.8.0. I was using 5.6.1 perl
and thus the problem.
hemuda@yahoogroups.com (Hemuda) wrote in message news:<20d93d09.0302071112.e422a63@posting.google.com>...
> Hello Gurus,
>
> My question is regarding the usage of $^N. It does not seem to work as
> expected. I have read the regex man page but it doesen't help
>
> $_ has a string which had s as the start of my regex and e as the end of my
> regex. The regex is trying to capture all
> chars matching \w and seperated by , (between the start s and ending e) in
> @list. Please see my session in the debugger at the bottom.
>
> My question is why $^N is not working? (And why is it printing some
> messages.)
>
> Thanks a lot,
> Hemant
>
> ----------------------------------------------------------------------------
> -------------------------------------
> DB<1> $_ = 'l,m sa,b,c,de x,y,z sl,m,n,o,pe %s% s0,1,2,3,4,5,6e %e% h,i'
>
> DB<2> use Data::Dumper
>
> DB<3> m/s(?:(\w),(?{ local @m = (@m, $^N); }))+(\w)e(?{ @list =@m})/
> via UNIVERSAL: VERSION
> via UNIVERSAL: can
> via UNIVERSAL: isa
> DB<4> p Dumper ( \@list)
> $VAR1 = [
> undef,
> undef,
> undef
> ];
>
> DB<5> m/s(?:(\w),(?{ local @m = (@m, $1); }))+(\w)e(?{ @list =@m})/
> via UNIVERSAL: VERSION
> via UNIVERSAL: can
> via UNIVERSAL: isa
> DB<6> p Dumper ( \@list)
> $VAR1 = [
> 'a',
> 'b',
> 'c'
> ];
------------------------------
Date: Sat, 08 Feb 2003 19:33:53 +0100
From: "Janek Schleicher" <bigj@kamelfreund.de>
Subject: Re: Using $^N in Regular Expressions
Message-Id: <pan.2003.02.08.12.56.54.288170@kamelfreund.de>
On Fri, 07 Feb 2003 15:18:40 -0500, Benjamin Goldberg wrote:
> Hemuda wrote:
>>
>> Hello Gurus,
>>
>> My question is regarding the usage of $^N. It does not seem to work as
>> expected. I have read the regex man page but it doesen't help
>
> I don't see any $^N in either of perldoc perlre, nor in perldoc perlvar.
> I do see a $^R variable in both, but no $^N.
>
> What is this variable, and what do you expect it to do?
It was invented in Perl 5.8.0.
From perldoc perlvar:
$^N The text matched by the used group most-recently
closed (i.e. the group with the rightmost closing
parenthesis) of the last successful search
pattern. (Mnemonic: the (possibly) Nested
parenthesis that most recently closed.)
This is primarily used inside "(?{...})" blocks
for examining text recently matched. For example,
to effectively capture text to a variable (in
addition to $1, $2, etc.), replace "(...)" with
(?:(...)(?{ $var = $^N }))
By setting and then using $var in this way
relieves you from having to worry about exactly
which numbered set of parentheses they are.
This variable is dynamically scoped to the current
BLOCK.
Cheerio,
Janek
------------------------------
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 4543
***************************************