command line

L

luc

I am trying to understand perls command line in dos(xp). I would simple want
to send hello to the screen. I've tried things like: perl -ew "print
\"hello\";"
perl -ew "print 'hello';"
What are perls rules here in the dos command line? Is there any
site/tutorial on this subject?
 
B

Bill

luc said:
I am trying to understand perls command line in dos(xp). I would simple want
to send hello to the screen. I've tried things like: perl -ew "print
\"hello\";"
perl -ew "print 'hello';"
What are perls rules here in the dos command line? Is there any
site/tutorial on this subject?
From the ActiveState perl docs:
-----
Why doesn't 'perl -e' work?
It does - it's just that some command shells (for example COMMAND.COM,
CMD.EXE and 4DOS) don't accept single quotes wrapped around command
arguments.

The safest way to do perl one-liners is to wrap the parameters within ""
(double-quotes) the use q() and qq() inside the parameters. q() and qq()
with put whatever is inside them between single-quotes or double-quotes,
respectively.
For example:

perl -e "use LWP::Simple; while(@c = head <>) { $c = join qq(\n\t), @c;
print qq(Header info:\n\t$c\n); }"

(this was all one line)
 
L

luc

Bill said:
From the ActiveState perl docs:
-----
Why doesn't 'perl -e' work?
It does - it's just that some command shells (for example COMMAND.COM,
CMD.EXE and 4DOS) don't accept single quotes wrapped around command
arguments.

The safest way to do perl one-liners is to wrap the parameters within ""
(double-quotes) the use q() and qq() inside the parameters. q() and qq()
with put whatever is inside them between single-quotes or double-quotes,
respectively.
For example:

perl -e "use LWP::Simple; while(@c = head <>) { $c = join qq(\n\t), @c;
print qq(Header info:\n\t$c\n); }"

(this was all one line)


So, how can I put the word hello to the screen in a one liner then?
 
L

luc

Bernard El-Hagin said:
Change -ew to -we in both examples. For more information:


perldoc perlrun

Thanks Bernard.
So if you would like to rename a list of files with a .txt extension to a
..pl extension, you could use the following command: print -we "rename
'*.txt','*.pl';"? This however doesn't work. How can you rename a series of
files(without using the default variable!) in a one liner?
 
D

Dan Wilga

luc said:
I am trying to understand perls command line in dos(xp). I would simple want
to send hello to the screen. I've tried things like: perl -ew "print
\"hello\";"
perl -ew "print 'hello';"
What are perls rules here in the dos command line? Is there any
site/tutorial on this subject?

IMHO, your best bet is to get a real commandline interpreter, like any
Unixy shell under Cygwin:

http://www.cygwin.com
 
L

luc

Bernard El-Hagin said:
I understand nothing of what you just said, except that you want to
rename some files, which has nothing to do with Print...I mean Perl.

sorry, typo...

So if you would like to rename a list of files with a .txt
extension to a .pl extension, you could use the following command:
perl -we "rename '*.txt','*.pl';"? This however doesn't work. How
can you rename a series of files(without using the default
variable!) in a one liner?
 
J

Jürgen Exner

luc said:
So if you would like to rename a list of files with a .txt extension
to a .pl extension, you could use the following command: print -we
"rename '*.txt','*.pl';"? This however doesn't work.

Assuming you meant to write
perl -we "rename '*.txt','*.pl';"
did you read the man page for the rename function? It will rename _one_
file!

Furthermore the DOS shell (in an earlier post you mentioned that you are on
Windows) doesn't know anything about wildcards. Therefore the '*' will not
be expanded as it would be on e.g. most Unix shells and as you seem to
expect. In other words you are trying to rename the file with the literal
name '*.txt'. I guess this is not what you want.
How can you
rename a series of files(without using the default variable!) in a
one liner?

Well, you will have to use glob() and a loop to get the names of all the
files and then loop through them.

jue
 
C

Cor Rosielle

Watch the sequence of your options. This doesn't work:
perl -ew "print 'hello'"
but this does:
perl -we "print 'hello'"

Cor
 
C

Cor Rosielle

Watch the sequence of your options. This doesn't work:
perl -ew "print 'hello'"
but this does:
perl -we "print 'hello'"

Cor
 
U

Uri Guttman

CR> Watch the sequence of your options. This doesn't work:
CR> perl -ew "print 'hello'"

well, -e take the next arg as the code so that would be 'w'. what else
is new?

uri
 
L

l v

luc said:
Thanks Bernard.
So if you would like to rename a list of files with a .txt extension to a
.pl extension, you could use the following command: print -we "rename
'*.txt','*.pl';"? This however doesn't work. How can you rename a series of
files(without using the default variable!) in a one liner?

The dos for command may be of interest to you. If you are on NT and
above the dos command ren *.txt *.pl should work, or perl -we "`ren
*.txt *.pl`". If looking for a Perl solution, although not the
prettiest and *may not* be what you are looking for:
dir /b|perl -nlwe "($n = $_) =~ s/\.txt$/\.pl/i; `ren $_ $n`"

Len
 
J

Joe Smith

luc said:
So if you would like to rename a list of files with a .txt extension to a
.pl extension, you could use the following command: print -we "rename
'*.txt','*.pl';"? This however doesn't work. How can you rename a series of
files(without using the default variable!) in a one liner?

It is possible to do it in less than 80 characters, but you will need to
use variables.

C:>perl -le "for(<*.txt>){$f=$_;s/txt$/pl/;print $f,'=',(rename $f,$_)?$_:$!}"

-Joe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,147
Messages
2,570,833
Members
47,378
Latest member
BlakeLig

Latest Threads

Top