One liner
Hi, ls | perl -ne 'print if /\.$/'| sed 's/\(.*\)/mv & \1jpg/' | sh I concocted the above command to change files named A1234. to A1234.jpg Is there a pure perl one-liner for this? Just curious. Thanx, Dp.
Re: One liner
Dermot wrote: > Hi, > > ls | perl -ne 'print if /\.$/'| sed 's/\(.*\)/mv & \1jpg/' | sh > > > I concocted the above command to change files named > > A1234. to A1234.jpg > > Is there a pure perl one-liner for this? Just curious. > > Thanx, > Dp. > perl -e 'rename $_, $_."jpg" foreach (glob "*.")' regards robert -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: One liner
Dermot wrote: Hi, Hello, ls | perl -ne 'print if /\.$/'| sed 's/\(.*\)/mv & \1jpg/' | sh I concocted the above command to change files named A1234. to A1234.jpg Is there a pure perl one-liner for this? Just curious. perl -e'rename$_,"${_}jpg"or warn"$_: $!"for<*.>' John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order.-- Larry Wall -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: cgi upload -> XMLin
Chas. Owens wrote: The XMLin method takes a string, file, or file handle as its argument. Just pass $upload_filehandle to it: my $ref = $xs->XMLin($cgi->upload("filename")); print $xs->XMLout($ref); Hi Thanks for replying. To be honest, I did try that, but then i was getting this message. read on filehandle failed: Undefined subroutine Fh::read at /usr/lib/perl5/XML/LibXML.pm line 531 at /usr/lib/perl5/XML/LibXML/SAX.pm line 64 at /usr/share/perl5/XML/Simple.pm line 366 I dont mind creating the tmp file, I just think its a very crappy way of doing things. Thanks again Brent Clark -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Newbie File Question....
On a unix/linux file system you see the following: $ ls -la total 244 drwx--9 rcoops ddao24096 Feb 13 09:40 . drwxr-xr-x 39 root root 4096 Feb 11 13:23 .. -rw---1 rcoops ddao2 158310 Feb 13 09:40 .bash_history -rw-r--r--1 rcoops ddao2 24 Apr 25 2006 .bash_logout -rw-r--r--1 rcoops ddao21228 Sep 12 12:08 .bash_profile -rw-r--r--1 rcoops ddao2 169 Nov 20 17:12 .bashrc On a windows file system you will see: H:\>dir Volume in drive H is rcoops$ Volume Serial Number is 2B01-1BEE Directory of H:\ 02/05/2008 04:38 PM Desktop 01/30/2008 01:49 PM My Documents 02/08/2008 10:28 AM WINDOWS 12/04/2006 05:32 PM Program Files On both file systems (on the command line) if you want to go one directory up you type: cd .. so the ../file.txt means from the current working directory (usually where your perl script is started from) go one directory up and access file.txt As for the ./file.txt this means as much as: in the current directory a file called file.txt if this is not found an error is thrown. If you type just file.txt your OS will look in the working directory and then look in the directories specified in the PATH environment variable. So it does nothing more then indicate to your OS which directory it needs to look. (I am sure there is a far more extensive and more precise way of explaining this but this is the simplest to understand and correct for most intents and purposes) I hope this helps a little bit. Rob On Feb 13, 2008 5:34 PM, <[EMAIL PROTECTED]> wrote: > I've been going over some listings and I found code > > like the following: > > > > "./directory/file.txt" and > > "../directory/file.txt" > > > > but I've never seen the "./" and "../" things at the > > beginning of the path. I've tried to google these > > but had no luck. I've googled "file specification" and > > "directory specification" and got a lot of hits on stuff > > but nothing on what those symbols mean. So, I thought > > I'd ask hereso if you wouldn't mind explaining what > > they are to a newbie I'd appreciate it very much. Thank > > you. > > > > > Portions of this message may be confidential under an exemption to Ohio's > public records law or under a legal privilege. If you have received this > message in error or due to an unauthorized transmission or interception, > please delete all copies from your system without disclosing, copying, or > transmitting this message. >
Re: Newbie File Question....
On Feb 13, 2008 8:34 AM, <[EMAIL PROTECTED]> wrote: > I've been going over some listings and I found code > > like the following: > > > > "./directory/file.txt" and > > "../directory/file.txt" > > > > but I've never seen the "./" and "../" things at the > > beginning of the path. I've tried to google these > > but had no luck. I've googled "file specification" and > > "directory specification" and got a lot of hits on stuff > > but nothing on what those symbols mean. So, I thought > > I'd ask hereso if you wouldn't mind explaining what > > they are to a newbie I'd appreciate it very much. Thank > > you. > > > That has less to do with perl than with the OS and how you navigate through directories. "./" refers to the current directory you are in so if you type "./file" it will look for file in your current location. "./directory/file.txt" refers to file.txt under "director" under your current location. Similarly ../ refers to parent directory. See http://en.wikipedia.org/wiki/Path_%28computing%29 for more info. I'd suggest looking up unix/linux basics on google. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Newbie File Question....
I've been going over some listings and I found code like the following: "./directory/file.txt" and "../directory/file.txt" but I've never seen the "./" and "../" things at the beginning of the path. I've tried to google these but had no luck. I've googled "file specification" and "directory specification" and got a lot of hits on stuff but nothing on what those symbols mean. So, I thought I'd ask hereso if you wouldn't mind explaining what they are to a newbie I'd appreciate it very much. Thank you. Portions of this message may be confidential under an exemption to Ohio's public records law or under a legal privilege. If you have received this message in error or due to an unauthorized transmission or interception, please delete all copies from your system without disclosing, copying, or transmitting this message.
Re: Newbie File Question....
[EMAIL PROTECTED] told me on 02/13/2008 10:34 AM: > I've been going over some listings and I found code > > like the following: > > > > "./directory/file.txt" and > > "../directory/file.txt" > > > > but I've never seen the "./" and "../" things at the > > beginning of the path. I've tried to google these > > but had no luck. I've googled "file specification" and > > "directory specification" and got a lot of hits on stuff > > but nothing on what those symbols mean. So, I thought > > I'd ask hereso if you wouldn't mind explaining what > > they are to a newbie I'd appreciate it very much. Thank > > you. > > "./" refers to the directory you are in. "../" refers to the parent to the directory you are in, or the one right above you. Assume you are in /home/rcopits and you had several directories, this that, other. The full paths would be /home/rcopits/this /home/rcopits/that /home/rcopits/other If you were in the 'other' directory and you wanted to run a script you just wrote, you could use "./script.sh" instead of "/home/rcopits/other/script.sh" If you wanted to run a script in "this" directory without moving, you could use "../this/script2.sh" instead of having to type "/home/rcopits/this/script2.sh" I hope that makes sense. Michael -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Newbie File Question....
On 02/13/2008 11:34:56 AM, [EMAIL PROTECTED] wrote: -> I've been going over some listings and I found code -> -> like the following: -> -> -> -> "./directory/file.txt" and -> -> "../directory/file.txt" this is not really a perl question, but since perl does respect the reference: "." and ".." are relative directories. They ALSO have a real (absolute) name. "." refers to the directory in question, eg. your present working directory (pwd). So if you cd to /home/mine, "." now refers to /home/mine (that's the real name). ".." refers to the directory above "." in a hierarchy. In /home/mine ".." would refer to /home. You really need to find a simple explanation of the unix filesystem, of which i am sure there are many on the web; otherwise you are going to have have more problems. Also try: www.ss64.com/bash/ which explains shell commands like ls and cd, since those commands do not have their own manual pages. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: cgi upload -> XMLin
On Feb 13, 2008 12:52 AM, Brent Clark <[EMAIL PROTECTED]> wrote: > Chas. Owens wrote: > > > The XMLin method takes a string, file, or file handle as its argument. > > Just pass $upload_filehandle to it: > > > > my $ref = $xs->XMLin($cgi->upload("filename")); > > print $xs->XMLout($ref); > > Hi > > Thanks for replying. To be honest, I did try that, but then i was getting > this message. > > read on filehandle failed: Undefined subroutine Fh::read > at /usr/lib/perl5/XML/LibXML.pm line 531 at > /usr/lib/perl5/XML/LibXML/SAX.pm line 64 > at /usr/share/perl5/XML/Simple.pm line 366 > I can't say for sure, but my guess is that this has to do with $cgi->upload returning an array in list context. Try something like my $ref = $xs->XMLin(scalar($cgi->upload("filename"))); # or my $ref = $xs->XMLin(($cgi->upload("filename"))[0]); > I dont mind creating the tmp file, I just think its a very crappy way of > doing things. > Perhaps we could be more help if you told us why you think it's "crappy." Is this a security issue? A system resource issue? Also, we need to know in what way the standard idiom of passing an upload_hook to CGI->new and toggling the $use_tempfile flag, as described in the file upload section of the CGI.pm documentation fails to meet your needs in this specific case. It seems to me that something like the following would do: my $xml; $cgi = CGI->new(\&upload_hook, \$xml , 0); sub upload_hook { my ($filename, $buffer, $bytes_read, $xml) = @_; $$xml .= $buffer; } my $ref = $xs->XMLin($xml); HTH, -- jay -- This email and attachment(s): [ ] blogable; [ x ] ask first; [ ] private and confidential daggerquill [at] gmail [dot] com http://www.tuaw.com http://www.downloadsquad.com http://www.engatiki.org values of β will give rise to dom!
Re: Newbie File Question....
On Feb 13, 2008 12:30 PM, <[EMAIL PROTECTED]> wrote: > Thank you to all who replied to this requestnow I > understand! I appreciate the help and the courtesy > of the replies! Once againThank You!! "One more satisfied customer" -said somewhere sometime by merlyn. -- David Moreno - http://www.damog.net/ Yes, you can.
RE: Newbie File Question....
Thank you to all who replied to this requestnow I understand! I appreciate the help and the courtesy of the replies! Once againThank You!! -Original Message- From: Copits Dick Sent: Wednesday, February 13, 2008 11:35 AM To: beginners@perl.org Subject: Newbie File Question I've been going over some listings and I found code like the following: "./directory/file.txt" and "../directory/file.txt" but I've never seen the "./" and "../" things at the beginning of the path. I've tried to google these but had no luck. I've googled "file specification" and "directory specification" and got a lot of hits on stuff but nothing on what those symbols mean. So, I thought I'd ask hereso if you wouldn't mind explaining what they are to a newbie I'd appreciate it very much. Thank you. Portions of this message may be confidential under an exemption to Ohio's public records law or under a legal privilege. If you have received this message in error or due to an unauthorized transmission or interception, please delete all copies from your system without disclosing, copying, or transmitting this message. Portions of this message may be confidential under an exemption to Ohio's public records law or under a legal privilege. If you have received this message in error or due to an unauthorized transmission or interception, please delete all copies from your system without disclosing, copying, or transmitting this message. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: One liner
> "Robert" == Robert Leibl <[EMAIL PROTECTED]> writes: Robert> Dermot wrote: >> Hi, >> >> ls | perl -ne 'print if /\.$/'| sed 's/\(.*\)/mv & \1jpg/' | sh >> >> >> I concocted the above command to change files named >> >> A1234. to A1234.jpg >> >> Is there a pure perl one-liner for this? Just curious. >> >> Thanx, >> Dp. >> Robert> perl -e 'rename $_, $_."jpg" foreach (glob "*.")' Why the extra parens? Also, I write foreach as for, whether it's a for loop (like this isn't) or foreach loop (like this is). perl -e 'rename $_, "${_}jpg" for glob "*."' -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 <[EMAIL PROTECTED]> http://www.stonehenge.com/merlyn/> Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: order of command line switch?
On Feb 13, 2008 11:57 AM, ciwei <[EMAIL PROTECTED]> wrote: > hostA>ls > SUNWjassVRTSVRTSicsco VRTSvcs > emc SUNWmlibVRTSalloc VRTSjre VRTSvlicVRTSvxvm > > hostA>ls | perl -en 'print if /SUNW/' > > return nothing , while > > hostA>ls | perl -ne 'print if /SUNW/' > SUNWits > SUNWjass > SUNWmlib > SUNWrtvc > > so why the order of -n -e switch make the differience? > this is perl 5.8.4. > Thanks > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > http://learn.perl.org/ > > > I think the code between single quotes is like a parameter to -e switch so it has to be -ne 'code' instead of -en 'code' -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
order of command line switch?
hostA>ls SUNWjassVRTSVRTSicsco VRTSvcs emc SUNWmlibVRTSalloc VRTSjre VRTSvlicVRTSvxvm hostA>ls | perl -en 'print if /SUNW/' return nothing , while hostA>ls | perl -ne 'print if /SUNW/' SUNWits SUNWjass SUNWmlib SUNWrtvc so why the order of -n -e switch make the differience? this is perl 5.8.4. Thanks -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: order of command line switch?
On Feb 13, 2008 2:57 PM, ciwei <[EMAIL PROTECTED]> wrote: snip > so why the order of -n -e switch make the differience? > this is perl 5.8.4. > Thanks snip This is true in all versions of Perl. It is becuase you are allowed to have more than one -e option: perl -e 'print "read ";' -e 'print "the ";' -e 'print "fine ";' -e 'print "manual\n";' If you look at the syntax in perlrun* you will see that -e must be followed by a string. The letter n is being used as the string, so you program looks like this: #!/usr/bin/perl n and it is being passed "print if /SUNW/" in $ARGV[0]. A constant is a valid Perl program (n is a bareword, so it is being treated as "n" by the parser), but it doesn't do anything. You can see this more clearly by turning off barewords with the strict** pragma: perl -Mstrict -en 'print if /SUNW/' Bareword "n" not allowed while "strict subs" in use at -e line 1. Execution of -e aborted due to compilation errors. * perldoc perlrun or http://perldoc.perl.org/perlrun.html#SYNOPSIS ** perldoc strict or http://perldoc.perl.org/strict.html -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/