Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > oneliner failed on Win2k with space in path name

Reply
Thread Tools

oneliner failed on Win2k with space in path name

 
 
Xu Yang
Guest
Posts: n/a
 
      07-07-2003
Hi,

I have an oneliner Perl script (see below) works fine when the path
name is 8.3 format on Win2K, but failed after it operated on a path
name contains space:

c:\perl -e "while(<>) {if(/^define/){print $ARGV.#'.$_;}}" c:\usr\*.tt

If I change the "c:\usr" to "c:\program files", it failed with error:
Can't open c:\program files\*.tt.
I double quote the path, did not help either.

Is this because the old version (5.x) of perl I am using?


Xu
 
Reply With Quote
 
 
 
 
Mina Naguib
Guest
Posts: n/a
 
      07-07-2003
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Xu Yang wrote:
> Hi,
>
> I have an oneliner Perl script (see below) works fine when the path
> name is 8.3 format on Win2K, but failed after it operated on a path
> name contains space:
>
> c:\perl -e "while(<>) {if(/^define/){print $ARGV.#'.$_;}}" c:\usr\*.tt


A shorter version of this is:

perl -ne 'print "$ARGV.#$_" if /^define/'

> If I change the "c:\usr" to "c:\program files", it failed with error:
> Can't open c:\program files\*.tt.
> I double quote the path, did not help either.


I'm not 100% sure how filename globbing works under windows' shell, but try the old 8.3
compatability naming, it might work:

c:\progra~1\*.tt


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

iD8DBQE/CdB4eS99pGMif6wRAiJ4AJ9A2RRreI7fIl5HjNscETWpUsUOyQ CdEdBT
dlH3Nu72i4G3/IYh9YCJ+fc=
=k2QF
-----END PGP SIGNATURE-----

 
Reply With Quote
 
 
 
 
tnitzke
Guest
Posts: n/a
 
      07-07-2003
Xu Yang wrote:
:
: c:\perl -e "while(<>) {if(/^define/){print $ARGV.#'.$_;}}" c:\usr\*.tt
:
: If I change the "c:\usr" to "c:\program files", it failed with error:
: Can't open c:\program files\*.tt.
: I double quote the path, did not help either.
:

You'll want to quote your arguments when they contain spaces. Try the following.

perl -e "while(<>) {if(/^define/){print $ARGV.#'.$_;}}" "c:\program files\*.tt"

--------------
tnitzke
($_=qq-dfwbh%nxigh%obchvsf%dsfz%voqysfn-)=~tr+%o-za-mn+ a-y'+;eval
 
Reply With Quote
 
Bob Walton
Guest
Posts: n/a
 
      07-07-2003
Xu Yang wrote:

....


> I have an oneliner Perl script (see below) works fine when the path
> name is 8.3 format on Win2K, but failed after it operated on a path
> name contains space:
>
> c:\perl -e "while(<>) {if(/^define/){print $ARGV.#'.$_;}}" c:\usr\*.tt


'--------------------------------------------------^
*please* copy/paste working code, don't just type it in -- the above as
given doesn't compile because the # is seen as the start of a Perl
comment, resulting in unbalanced braces. I assume it should be ...'#'...


>
> If I change the "c:\usr" to "c:\program files", it failed with error:
> Can't open c:\program files\*.tt.
> I double quote the path, did not help either.
>
> Is this because the old version (5.x) of perl I am using?
>
>
> Xu
>


Your error message indicates that the command "shell" got the correct
filename, but that such a file was not actually present. Check in your
"c:\program files" directory and see if there are any *.tt files in that
directory. Usually, there aren't any files in that directory -- only
additional subdirectories. The problem should have nothing to do with
your version of Perl, and, in fact, doesn't appear to be a Perl problem
at all.

--
Bob Walton

 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      07-08-2003
Xu Yang <(E-Mail Removed)> wrote:

> I have an oneliner Perl script (see below) works fine

^^^^^^^^^^
^^^^^^^^^^
> c:\perl -e "while(<>) {if(/^define/){print $ARGV.#'.$_;}}" c:\usr\*.tt

^^^

I'm having trouble believing you there...

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


> Is this because the old version (5.x) of perl I am using?



No, it is because of the silly shell that you are forced to use.

You must expand the glob() in your Perl code, if your shell won't
expand it for you. Something like:

c:\perl -ne "BEGIN{ @ARGV=<$ARGV[0]> } print qq($ARGV#$_) if /^define/" *.tt


--
Tad McClellan SGML consulting
http://www.velocityreviews.com/forums/(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
Xu Yang
Guest
Posts: n/a
 
      07-08-2003
All,
Thanks for the help from everyone!
I would apologize for my careless when I post my code, the left single
quote around the # was missed when I cut and paste.
the shortname does work as everyone expected. But I have to do more
work from the code who calls this oneliner in order to get the short
name. I was thinking use the Win32's GetShortName(), unfortunately,
the old version Perl I have does not have this call. So I end up with
converting the long name to short name.

Thanks again.
Xu

Mina Naguib <(E-Mail Removed)> wrote in message news:<XfkOa.36870$(E-Mail Removed) >...
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Xu Yang wrote:
> > Hi,
> >
> > I have an oneliner Perl script (see below) works fine when the path
> > name is 8.3 format on Win2K, but failed after it operated on a path
> > name contains space:
> >
> > c:\perl -e "while(<>) {if(/^define/){print $ARGV.#'.$_;}}" c:\usr\*.tt

>
> A shorter version of this is:
>
> perl -ne 'print "$ARGV.#$_" if /^define/'
>
> > If I change the "c:\usr" to "c:\program files", it failed with error:
> > Can't open c:\program files\*.tt.
> > I double quote the path, did not help either.

>
> I'm not 100% sure how filename globbing works under windows' shell, but try the old 8.3
> compatability naming, it might work:
>
> c:\progra~1\*.tt
>
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.2.1 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iD8DBQE/CdB4eS99pGMif6wRAiJ4AJ9A2RRreI7fIl5HjNscETWpUsUOyQ CdEdBT
> dlH3Nu72i4G3/IYh9YCJ+fc=
> =k2QF
> -----END PGP SIGNATURE-----

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"number-in-base" ``oneliner'' Alex Martelli Python 21 11-01-2004 02:07 PM
Why Python style guide (PEP-8) says 4 space indents instead of 8 space??? 8 space indents ever ok?? Christian Seberino Python 21 10-27-2003 04:20 PM
Re: Why Python style guide (PEP-8) says 4 space indents instead of8 space??? 8 space indents ever ok?? Ian Bicking Python 2 10-24-2003 11:15 AM
Re: Why Python style guide (PEP-8) says 4 space indents instead of8 space??? 8 space indents ever ok?? Ian Bicking Python 2 10-23-2003 07:07 AM
Stack space, global space, heap space Shuo Xiang C Programming 10 07-11-2003 07:30 PM



Advertisments