[28804] in Perl-Users-Digest
Perl-Users Digest, Issue: 48 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jan 18 21:06:02 2007
Date: Thu, 18 Jan 2007 18:05:05 -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 Thu, 18 Jan 2007 Volume: 11 Number: 48
Today's topics:
Can't get output from pipe with autoflush on <stahl.karl@gmail.com>
Re: help problemes cgi and GD::Text <john.swilting@wanadoo.fr>
Re: Map Windows from Unix <m@remove.this.part.rtij.nl>
Re: Map Windows from Unix <chad@chadhanna.co.uk>
Re: need help with the tr and s/// <novafyre@hotmail.com>
Re: need help with the tr and s/// <bik.mido@tiscalinet.it>
Re: need help with the tr and s/// <novafyre@hotmail.com>
Re: need help with the tr and s/// <tadmc@augustmail.com>
Re: Perl + Java krakle@visto.com
Re: Perl + Java <glex_no-spam@qwest-spam-no.invalid>
Re: Perl + Java <cwilbur@chromatico.net>
Re: perl + Win32::OLE + regex = bug <mark.clementsREMOVETHIS@wanadoo.fr>
Re: Regexp for parsing windows filepath on Unix <john@castleamber.com>
Re: Regexp for parsing windows filepath on Unix <mritty@gmail.com>
Re: Regexp for parsing windows filepath on Unix Milagro
Re: Regexp for parsing windows filepath on Unix <john@castleamber.com>
Re: Regexp for parsing windows filepath on Unix <bik.mido@tiscalinet.it>
Re: Regexp for parsing windows filepath on Unix <john@castleamber.com>
Re: Regexp for parsing windows filepath on Unix <kkeller-usenet@wombat.san-francisco.ca.us>
Re: Regexp for parsing windows filepath on Unix <john@castleamber.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 18 Jan 2007 15:04:29 -0800
From: "Ishmael" <stahl.karl@gmail.com>
Subject: Can't get output from pipe with autoflush on
Message-Id: <1169161468.507502.147560@l53g2000cwa.googlegroups.com>
Howdy,
I'm trying to get a list of clients/users on my network using 'rusers'.
When I run 'rusers' from the command line, the behavior is as follows:
First, it instantaneously prints list of clients/users (perfect) THEN
it hangs for several seconds (I think this is due to a problem with the
client database configuration, over which I have no control). In any
case, I would like to time out the function after a second or so, keep
the first chunk of output, and kill the 'rusers' function.
Unfortunately, it seems as if the output does not become accessible via
the filehandle (see below) unless 'rusers' exits normally (which takes
too long). I've tried turning 'autoflush' on, but this doesn't seem to
work.
Any help would be greatly appreciated! Here's the code:
undef $/; # Try eliminating OUTPUT_RECORD_SEPARATOR
print "Getting user list via rusers\n";
my ($pid, $rusers_out, @tmp);
eval {
local $SIG{ALRM} = sub { die "alarm clock restart\n" };
alarm $rusers_timeout;
eval {
$pid = open F, "rusers -a |" or die "rusers gave error: $!";
F->autoflush(1);
$rusers_out = <F>;
};
alarm 0;
if ($@) {
if ($@ =~ /alarm clock restart/) {
die "'rusers' timed out.\n"; # Create an exception to get out of
outer loop.
}
else {
die($@);
}
}
};
alarm 0;
if ( $@ ne '' ) {
print "$@";
# kill PID with a TERM (terminate) signal. Note: Control-C (INT
signal) also works.
my $num_successfully_killed = kill('TERM', $pid);
if ($num_successfully_killed != 1) {
print "Error: Could not kill rusers after timeout\n";
}
}
print "RUSERS OUTPUT: $rusers_out\n"; # Nothing gets here
exit;
------------------------------
Date: Thu, 18 Jan 2007 20:35:53 +0100
From: "john.swilting" <john.swilting@wanadoo.fr>
Subject: Re: help problemes cgi and GD::Text
Message-Id: <45afcc11$0$25936$ba4acef3@news.orange.fr>
john.swilting wrote:
> How to use GD::Text
> The documentation says
>
> my $gd_text = GD::Text->new(
> text => 'Some text',
> font => 'funny.ttf',
> ptsize => 14,
> );
>
> And I have
>
> #!/usr/bin/perl -w
>
> use strict;
> use diagnostics;
> use GD;
> ##use GD::Text;
> use CGI;
> use CGI::Carp;
>
> my $q = new CGI;
>
> # create a new
>
> my $im = new GD::Image(100,100);
>
> # allocate some colors
> my $white = $im->colorAllocate(255,255,255);
> my $black = $im->colorAllocate(0,0,0);
> my $red = $im->colorAllocate(255,0,0);
> my $blue = $im->colorAllocate(0,0,255);
>
> # make the background tra $im_pngnsparent and interlaced
> $im->transparent($white);
> $im->interlaced('true');
>
> # put a black frame around the picture
> $im->rectangle(0,0,99,99,$black);
>
> # draw a blue oval
> $im->arc(50,50,95,75,0,360,$blue);
>
> # and fill it with red
> $im->fill(50,50,$red);
>
> print $q->header( -type => "image/png", -expires => "-1d");
> binmode STDOUT;
> print $im->png
>
>
> How to make
> So that both work together
I am going to go to bed
I return within 24 hours
I do not indeed have to look in for the doc I believe
------------------------------
Date: Thu, 18 Jan 2007 21:24:40 +0100
From: Martijn Lievaart <m@remove.this.part.rtij.nl>
Subject: Re: Map Windows from Unix
Message-Id: <pan.2007.01.18.20.24.40.667048@remove.this.part.rtij.nl>
On Wed, 17 Jan 2007 21:57:42 -0600, Andrew DeFaria wrote:
> Martijn Lievaart wrote:
>>> I'm not sure what you mean by a "cifs" capable kernel.
>> The fact that you don't know what a cifs capable kernel is shows the
>> depth of your knowledge.
> I was merely asking for clarification. Your ever so expert, social and
> helpful self replied what again?
Well, the answer was just above it, in the part that you snipped. Reading
is also not one of your strong points obviously.
>>> I've used Samba to mount a remote share from a Windows PC and it
>>> worked just fine.
>> Are you dense or lying deliberately?
> The statement above is 100% true. Of course you'll never believe me...
No I don't. Samba *exports* smb shares.
M4
--
Redundancy is a great way to introduce more single points of failure.
------------------------------
Date: Thu, 18 Jan 2007 22:19:44 +0000
From: Chad Hanna <chad@chadhanna.co.uk>
Subject: Re: Map Windows from Unix
Message-Id: <eoorpv$89g$1$8300dec7@news.demon.co.uk>
Martijn Lievaart wrote:
> On Wed, 17 Jan 2007 21:57:42 -0600, Andrew DeFaria wrote:
>
>> Martijn Lievaart wrote:
>>>> I'm not sure what you mean by a "cifs" capable kernel.
>>> The fact that you don't know what a cifs capable kernel is shows the
>>> depth of your knowledge.
>> I was merely asking for clarification. Your ever so expert, social and
>> helpful self replied what again?
>
> Well, the answer was just above it, in the part that you snipped. Reading
> is also not one of your strong points obviously.
>
>>>> I've used Samba to mount a remote share from a Windows PC and it
>>>> worked just fine.
>>> Are you dense or lying deliberately?
>> The statement above is 100% true. Of course you'll never believe me...
>
> No I don't. Samba *exports* smb shares.
>
> M4
Just to satisfy my own curiousity I checked out the Samba web site -
it's been some years since I needed this - though I was aware of the
smbclient utility distributed with Samba and may even have used it once.
[ObPerl - checking CPAN there seem to be modules to work with both Samba
and SmbClient even authentication ]
Nevertheless on the current Samba web site at
http://us3.samba.org/samba/docs/SambaIntro.html it does mention "SMB
filesystems on Linux", namely the "smbfs distributed with Samba as a
courtesy" and the developing smbsh SMB shell. Wonder if it works on
FreeBSD?
Thank you for making me look into this again :-/
--
Chad Hanna
Systems Developer FamilyHistoryOnline www.familyhistoryonline.net
FreeBSD Apache MySQL Perl mod_perl PHP
------------------------------
Date: Thu, 18 Jan 2007 12:40:27 -0700
From: Mark Donovan <novafyre@hotmail.com>
Subject: Re: need help with the tr and s///
Message-Id: <C1D51B3B.9518%novafyre@hotmail.com>
You are right, of course, but the four line version was for illustration
purposes. I believe the individual steps make the more compact alternatives
easier to understand.
--
Mark
On 1/18/07 04:19, "Michele Dondi" <bik.mido@tiscalinet.it> wrote:
> On Wed, 17 Jan 2007 19:21:15 -0700, Mark Donovan
> <novafyre@hotmail.com> wrote:
>>
>> $s1 =~ m/(0*)\z/;
>> $len = length $1;
>> $s2 =~ s/(.*?)0*\z/$1/;
>> $s2 .= '0' x $len;
>
> This amounts to getting a string of zeroes, getting its length and
> rebuild it based on this length, there's clearly an unnecessary
> passage:
>
> my ($pad) = $s1 =~ /(0*)\z/g;
> $s2 =~ s/(.*?)0*\z/$1$pad/;
------------------------------
Date: Thu, 18 Jan 2007 23:13:32 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: need help with the tr and s///
Message-Id: <6trvq29h5jthgpiku4hees7aagvd9ta7ic@4ax.com>
On Thu, 18 Jan 2007 12:40:27 -0700, Mark Donovan
<novafyre@hotmail.com> wrote:
>You are right, of course, but the four line version was for illustration
>purposes. I believe the individual steps make the more compact alternatives
>easier to understand.
I believe individual steps make things easier to understand too, but
*not* steps that arbitrarily do and undo stuff. Taking the length of a
string to build the same string to pad with zeroes, whereas the first
string would do in the first place, simply does not fit there.
>On 1/18/07 04:19, "Michele Dondi" <bik.mido@tiscalinet.it> wrote:
[snip (to)fu]
*Please* do not top-post!
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Thu, 18 Jan 2007 16:36:58 -0700
From: Mark Donovan <novafyre@hotmail.com>
Subject: Re: need help with the tr and s///
Message-Id: <C1D552AA.9544%novafyre@hotmail.com>
If the purpose of illustration isn't clear to you, I'm happy to explain.
As a matter of preference and for purposes of illustration, I carefully
chose the steps I used so that the person asking the question could insert
print statements, if needed, so that each step would be clear. The original
question indicated to me that zim is familiar with a C-like programming
language. To me, the extra steps are helpful to someone who may not be
familiar with the substitution features of perl. The extra steps allow
someone to examine the intermediate results. Moreover, my answer included a
method that avoided the extra steps. But for my purpose of illustrating the
method, your assertion is simply wrong.
As to your other remark, I find it irrelevant and refer you and others to
the posting guidelines for this newsgroup. Specifically, the "first
guidelines commandment" which I'll quote for you.
> A note to newsgroup "regulars":
> Do not use these guidelines as a "license to flame" or other
> meanness. It is possible that a poster is unaware of things
> discussed here. Give them the benefit of the doubt, and just
> help them learn how to post, rather than assume that they do
> know and are being the "bad kind" of Lazy.
You may have noticed that when I replied to the original question, I placed
my reply after the material I quoted. I did it for a good reason.
In a general sense, there *is* a good reason for posting replies after
quoted text. It is to help others who may read the message to follow the
revisions or sequence of changes that others have suggested. Beyond that,
however, placing a reply above or below quoted material is a matter of
personal preference. There is no program code that is relevant from your
reply, you simply failed to understand my purpose in showing individual
steps of the method I used.
You should understand that placing the word *please* in front of a sentence
does not make a rude and irrelevant demand into a polite request. You are
not enforcing rules. There's a line from the first "Pirates of the
Caribbean" movie, "the Code is more what you'd call 'guidelines' than actual
rules."
The posting guidelines for this newsgroup are guidelines, not rules. You
will find people, who for their own reasons, may not follow the guidelines
100 percent of the time. It's best to assume there may be a reason and avoid
making irrelevant remarks.
If you prefer more authoritative standards than the posting guidelines, I
refer you to:
"Netiquette Guidelines," http://rfc.net/rfc1855.html
http://en.wikipedia.org/wiki/Etiquette
http://en.wikipedia.org/wiki/Manners
http://www.campaignforcourtesy.org/
--
Regards,
Mark
On 1/18/07 15:13, "Michele Dondi" <bik.mido@tiscalinet.it> wrote:
> On Thu, 18 Jan 2007 12:40:27 -0700, Mark Donovan
> <novafyre@hotmail.com> wrote:
>
> I believe individual steps make things easier to understand too, but
> *not* steps that arbitrarily do and undo stuff. Taking the length of a
> string to build the same string to pad with zeroes, whereas the first
> string would do in the first place, simply does not fit there.
>
> *Please* do not top-post!
>
------------------------------
Date: Thu, 18 Jan 2007 19:17:59 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: need help with the tr and s///
Message-Id: <slrner0727.lpu.tadmc@tadmc30.august.net>
Mark Donovan <novafyre@hotmail.com> wrote:
> If the purpose of illustration isn't clear to you, I'm happy to explain.
What illustration?
> As to your other remark,
What other remark?
> I find it irrelevant and refer you and others to
> the posting guidelines for this newsgroup. Specifically, the "first
> guidelines commandment" which I'll quote for you.
>
>> A note to newsgroup "regulars":
>> Do not use these guidelines as a "license to flame" or other
>> meanness. It is possible that a poster is unaware of things
>> discussed here. Give them the benefit of the doubt, and just
>> help them learn how to post, rather than assume that they do
>> know and are being the "bad kind" of Lazy.
I find your quote irrelevant, as there was no flaming or other meanness.
> You may have noticed that when I replied to the original question, I placed
> my reply after the material I quoted. I did it for a good reason.
And that reason has now stopped applying?
What changed?
> In a general sense, there *is* a good reason for posting replies after
> quoted text.
So why not just do that then?
What's all the hubbub about?
> It is to help others who may read the message to follow the
> revisions or sequence of changes that others have suggested.
Right. Like what illustration and what remark.
> Beyond that,
> however, placing a reply above or below quoted material is a matter of
> personal preference.
I exercise my personal preference by killfiling top-posters.
> There is no program code that is relevant from your
> reply,
But there was other context that _was_ relevant in the previous replies.
> You should understand that placing the word *please* in front of a sentence
> does not make a rude and irrelevant demand into a polite request.
Requesting that you not top post is neither rude nor irrelevant.
> The posting guidelines for this newsgroup are guidelines, not rules.
But there are (often unspoken) consequences should you choose to
not follow them.
> You
> will find people, who for their own reasons, may not follow the guidelines
> 100 percent of the time.
That is their choice.
> It's best to assume there may be a reason and avoid
> making irrelevant remarks.
I find it best to simply auto-ignore whiners.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 18 Jan 2007 15:00:38 -0800
From: krakle@visto.com
Subject: Re: Perl + Java
Message-Id: <1169161238.342578.37520@s34g2000cwa.googlegroups.com>
On Jan 18, 10:08 am, Michele Dondi <bik.m...@tiscalinet.it> wrote:
> On 18 Jan 2007 05:06:04 -0800, corriek...@hotmail.com wrote:
>
> >Is it possible to call a java program from within my perl code and use
> >the return value from the java program in my perl program?Yes. More precisely you can use system() to run a program regardless
> of the language it is written in, and inspect its return value to find
> the exit status - remember that you will have to shift it right by
> eight for the actual one.
>
> Michele
Isnt system somewhat of an expensive call?
------------------------------
Date: Thu, 18 Jan 2007 18:11:48 -0600
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Perl + Java
Message-Id: <45b00c2f$0$697$815e3792@news.qwest.net>
krakle@visto.com wrote:
>
> On Jan 18, 10:08 am, Michele Dondi <bik.m...@tiscalinet.it> wrote:
>> On 18 Jan 2007 05:06:04 -0800, corriek...@hotmail.com wrote:
>>
>>> Is it possible to call a java program from within my perl code and use
>>> the return value from the java program in my perl program?Yes. More precisely you can use system() to run a program regardless
>> of the language it is written in, and inspect its return value to find
>> the exit status - remember that you will have to shift it right by
>> eight for the actual one.
>>
>> Michele
>
> Isnt system somewhat of an expensive call?
>
It's on sale this week and this week only. :-)
------------------------------
Date: 18 Jan 2007 20:22:55 -0500
From: Charlton Wilbur <cwilbur@chromatico.net>
Subject: Re: Perl + Java
Message-Id: <87lkjz3j4g.fsf@mithril.chromatico.net>
>>>>> "k" == krakle <krakle@visto.com> writes:
k> Isnt system somewhat of an expensive call?
It's probably a safe bet that someone invoking Java from Perl is not
likely to be terribly concerned with the overhead of system().
Charlton
--
Charlton Wilbur
cwilbur@chromatico.net
------------------------------
Date: Thu, 18 Jan 2007 23:04:46 +0100
From: Mark Clements <mark.clementsREMOVETHIS@wanadoo.fr>
Subject: Re: perl + Win32::OLE + regex = bug
Message-Id: <45afeefe$0$27412$ba4acef3@news.orange.fr>
glob wrote:
> #!perl
> # highly butchered version of real-world code
> # just to demonstrate the issue.
> use strict;
> use Win32::OLE;
> my $field = 'bad@id';
> if ($field =~ /^([^\@]+)\@(.*)/) {
> my $dom = Win32::OLE->new('Msxml.DOMDocument');
> $dom->loadXml('<moo><bad id="1" /></moo>');
> $dom->documentElement->SelectSingleNode($1)->getAttribute($2);
> }
> my $desc = 'i am:testing';
> $desc =~ s/^([^:]+)/$1/;
> print "$desc\n";
> __END__
>
> this prints out "bad:testing", not "i am:testing".
>
> changing the SelectSingleNode calls to create a new string fixes the
> problem:
> $dom->documentElement->SelectSingleNode("$1")->getAttribute("$2");
>
> i found it interesting that the issue continues even thou $dom is out
> of scope.
>
> that is all, just had to share / vent. took me a while to track down.
For what it's worth, I've raised a bug.
http://rt.cpan.org/Ticket/Display.html?id=24442
Mark
------------------------------
Date: 18 Jan 2007 19:39:56 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: Regexp for parsing windows filepath on Unix
Message-Id: <Xns98BC8B02CBD00castleamber@130.133.1.4>
Milagro wrote:
> I've tried using various RegExp's but none of them work.
It helps to show them here. They work, but they don't match because you
made a mistake somewhere.
> I think I know
> why though -- when I try and print out the $fname variable before
> running any RegExp's on it, it prints back out without the slashes!
> Since "\" is a typical esc character It won't print it out unless I
> acually escape it first (C:\\My Documents\\My files\\file1.doc). I
> can't do that though because this filepath is being returned to me, I'm
> not creating it.
perl -e "my $path = 'C:\My Documents\My files\file1.doc'; my ( $doc ) =
$path =~ /([^\\]+)$/; print $doc"
file1.doc
/([^\\]+)$/;
means: capture everything that's not a \ at the end of $path.
You want to check the result before you use it to create a file etc.
--
John Experienced Perl programmer: http://castleamber.com/
Perl help, tutorials, and examples: http://johnbokma.com/perl/
------------------------------
Date: 18 Jan 2007 11:46:45 -0800
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Regexp for parsing windows filepath on Unix
Message-Id: <1169149605.385311.44650@l53g2000cwa.googlegroups.com>
Milagro wrote:
> I'm a fairly experienced perl programmer but am having problem with
> what should be a very simple regular expression. Here's the problem.
> I have a file coming into a Linux Box from a Win32 machine via Http.
> I'm able to capture the file and move it over intact to my Linux box
> with no problem. The problem comes when I try and check the filename
> for invalid characters before accepting it.
>
> I've discovered that when a user uploads the file with IE (not sure
> what version), the entire path to the file is sent (as opposed to
> FireFox which only returns the filename). So I'm left with something
> like this in my input variable when someone uploads:
> $fname = "C:\My Documents\My files\file1.doc";
No. Very much no. You definately do NOT have that coming in from your
upload. What you *may* have, however, is:
$fname = 'C:\My Documents\My files\file1.doc';
The difference between "" and '' is key. In your example, you're
saying you have a string that contains special chracters, such as a
form feed (the "\f"). In my single-quoted version, there are simply
slashes followed by the given character. If this path is coming from a
CGI parameter, you are given the correct string, the one I showed
there.
> I need to parse the line above so all I get is whatever is after the
> last slash; in this case "file1.doc".
> I've tried using various RegExp's but none of them work. I think I know
> why though -- when I try and print out the $fname variable before
> running any RegExp's on it, it prints back out without the slashes!
I don't believe you. Those slashes are part of the string. If they're
not there, it's because you've removed them.
> Since "\" is a typical esc character It won't print it out unless I
> acually escape it first (C:\\My Documents\\My files\\file1.doc). I
> can't do that though because this filepath is being returned to me, I'm
> not creating it.
>
No. You're mistaken. Backslahes are only special when typed into
string literals in the Perl code. Computed values, such as read from
user input or from a CGI parameter list, do not incur this
functionality. A backslash in a computed string is just a backslash.
> I've been trying many different things but so far none has worked.
And yet you haven't bothered to show us even *ONE* of those things, out
of the "many" that you've tried. How can we show you what you did
wrong? Your entire diagnosis about the problem is incorrect, so we
really need to see a short-but-complete script that we can correct to
show you where you went wrong.
> Thanks for any help you can give me!
While another poster gave you the best answer - use File::Basename
instead of a regexp - there is no reason that a regexp cannot solve
this problem. IF and only if the string actually is what you claim it
to be, this regexp would work fine:
s{^.*\\}{}g;
Without knowing what you actually did, though, it's really difficult to
help us help you fix it.
Paul Lalli
------------------------------
Date: Thu, 18 Jan 2007 16:14:35 -0500
From: Milagro
Subject: Re: Regexp for parsing windows filepath on Unix
Message-Id: <1169155001_809@news-east.n>
Thank you John and Paul. Your advice solved my problem.
Your correct by the way, I should have posted my non-working examples.
Next time I'll do just that.
In case your curious I had two problems.
1. The regular expressions I used were wrong. Not that the correct one
would have worked because... see #2
2. I was testing by writing a small perl script and I used double
quotes on the string I was testing instead of single quotes! Yeesh.
This is what happens when I watch my 2 year old son and try to program
at the same time.
Thanks again.
Mike
On 2007-01-18 14:46:45 -0500, "Paul Lalli" <mritty@gmail.com> said:
> Milagro wrote:
>> I'm a fairly experienced perl programmer but am having problem with
>> what should be a very simple regular expression. Here's the problem.
>> I have a file coming into a Linux Box from a Win32 machine via Http.
>> I'm able to capture the file and move it over intact to my Linux box
>> with no problem. The problem comes when I try and check the filename
>> for invalid characters before accepting it.
>>
>> I've discovered that when a user uploads the file with IE (not sure
>> what version), the entire path to the file is sent (as opposed to
>> FireFox which only returns the filename). So I'm left with something
>> like this in my input variable when someone uploads:
>> $fname = "C:\My Documents\My files\file1.doc";
>
> No. Very much no. You definately do NOT have that coming in from your
> upload. What you *may* have, however, is:
> $fname = 'C:\My Documents\My files\file1.doc';
>
> The difference between "" and '' is key. In your example, you're
> saying you have a string that contains special chracters, such as a
> form feed (the "\f"). In my single-quoted version, there are simply
> slashes followed by the given character. If this path is coming from a
> CGI parameter, you are given the correct string, the one I showed
> there.
>
>> I need to parse the line above so all I get is whatever is after the
>> last slash; in this case "file1.doc".
>> I've tried using various RegExp's but none of them work. I think I know
>> why though -- when I try and print out the $fname variable before
>> running any RegExp's on it, it prints back out without the slashes!
>
> I don't believe you. Those slashes are part of the string. If they're
> not there, it's because you've removed them.
>
>> Since "\" is a typical esc character It won't print it out unless I
>> acually escape it first (C:\\My Documents\\My files\\file1.doc). I
>> can't do that though because this filepath is being returned to me, I'm
>> not creating it.
>>
>
> No. You're mistaken. Backslahes are only special when typed into
> string literals in the Perl code. Computed values, such as read from
> user input or from a CGI parameter list, do not incur this
> functionality. A backslash in a computed string is just a backslash.
>
>> I've been trying many different things but so far none has worked.
>
> And yet you haven't bothered to show us even *ONE* of those things, out
> of the "many" that you've tried. How can we show you what you did
> wrong? Your entire diagnosis about the problem is incorrect, so we
> really need to see a short-but-complete script that we can correct to
> show you where you went wrong.
>
>> Thanks for any help you can give me!
>
> While another poster gave you the best answer - use File::Basename
> instead of a regexp - there is no reason that a regexp cannot solve
> this problem. IF and only if the string actually is what you claim it
> to be, this regexp would work fine:
>
> s{^.*\\}{}g;
>
> Without knowing what you actually did, though, it's really difficult to
> help us help you fix it.
>
> Paul Lalli
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
------------------------------
Date: 18 Jan 2007 21:16:24 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: Regexp for parsing windows filepath on Unix
Message-Id: <Xns98BC9B5DB3EC2castleamber@130.133.1.4>
"Paul Lalli" <mritty@gmail.com> wrote:
> While another poster gave you the best answer - use File::Basename
> instead of a regexp
Yup, just want to add that I also strongly suggest to use a module for
this, even though I posted a regex.
--
John Experienced Perl programmer: http://castleamber.com/
Perl help, tutorials, and examples: http://johnbokma.com/perl/
------------------------------
Date: Thu, 18 Jan 2007 23:22:13 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Regexp for parsing windows filepath on Unix
Message-Id: <ghsvq2de0gpfpqes4j5rmgdkolrjjce2k0@4ax.com>
On 18 Jan 2007 11:46:45 -0800, "Paul Lalli" <mritty@gmail.com> wrote:
>> Thanks for any help you can give me!
>
>While another poster gave you the best answer - use File::Basename
Just to stress the concept: I second that too.
>instead of a regexp - there is no reason that a regexp cannot solve
>this problem. IF and only if the string actually is what you claim it
>to be, this regexp would work fine:
>
>s{^.*\\}{}g;
And since another poster showed how to do it with a single C<m>,
here's YAWTDI:
my $name = (split /\\/)[-1];
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: 18 Jan 2007 22:22:33 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: Regexp for parsing windows filepath on Unix
Message-Id: <Xns98BCA6949FE94castleamber@130.133.1.4>
Milagro wrote:
> This is what happens when I watch my 2 year old son and try to program
> at the same time.
Been there, done that :-)
BTW, as you have seen it's common to reply under the part you're replying
to and remove all lines that are no longer needed, thanks.
--
John Experienced Perl programmer: http://castleamber.com/
Perl help, tutorials, and examples: http://johnbokma.com/perl/
------------------------------
Date: Thu, 18 Jan 2007 14:33:46 -0800
From: Keith Keller <kkeller-usenet@wombat.san-francisco.ca.us>
Subject: Re: Regexp for parsing windows filepath on Unix
Message-Id: <a79584xsv4.ln2@goaway.wombat.san-francisco.ca.us>
On 2007-01-18, Milagro <> wrote:
>
> This is what happens when I watch my 2 year old son and try to program
> at the same time.
Just wait till he wants to ''help'' you code. :) My 3yo made the
variable $connnnnnnnnnnnnnnnnnnnnnNNNNNNNNNNNNNNNNNNNNNNNNN .
Fortunately I had use strict turned on.
--keith
--
kkeller-usenet@wombat.san-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://www.therockgarden.ca/aolsfaq.txt
see X- headers for PGP signature information
------------------------------
Date: 18 Jan 2007 22:46:42 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: Regexp for parsing windows filepath on Unix
Message-Id: <Xns98BCAAACE3675castleamber@130.133.1.4>
Michele Dondi <bik.mido@tiscalinet.it> wrote:
> And since another poster showed how to do it with a single C<m>,
> here's YAWTDI:
>
> my $name = (split /\\/)[-1];
YAWTDI for those who don't want to use regexps all the time:
my $filename = 'C:\My Documents\My files\file1.doc';
my $leafname = substr( $filename, 1 + rindex( $filename, '\\' ) );
--
John Experienced Perl programmer: http://castleamber.com/
Perl help, tutorials, and examples: http://johnbokma.com/perl/
------------------------------
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 V11 Issue 48
*************************************