a perl question
cat asdf.txt bla-bla bla-bla bla[XYZ] importantthing another important thing [/XYZ] bla-bla bla-bla [XYZ] yet another thing hello! [/XYZ] bla-bla etc. $ SOMEPERLMAGIC asdf.txt output.txt $ cat output.txt importantthing another important thing yet another thing hello! how can i sovle this question? what is SOMEPERLMAGIC? are there any perl gurus, that have a little spare time? Thank you! :\ -- To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org Archive: http://lists.debian.org/847887.46702...@web121408.mail.ne1.yahoo.com
Re: a perl question
On Tue, 2011-01-04 at 02:27 -0800, S Mathias wrote: cat asdf.txt bla-bla bla-bla bla[XYZ] importantthing another important thing [/XYZ] bla-bla bla-bla [XYZ] yet another thing hello! [/XYZ] bla-bla etc. $ SOMEPERLMAGIC asdf.txt output.txt $ cat output.txt importantthing another important thing yet another thing hello! j...@squeeje:~$ cat asdf.txt bla-bla bla-bla bla[XYZ] importantthing another important thing [/XYZ] bla-bla bla-bla [XYZ] yet another thing hello! [/XYZ] bla-bla j...@squeeje:~$ j...@squeeje:~$ j...@squeeje:~$ j...@squeeje:~$ j...@squeeje:~$ cat asdf.txt | perl -e 'my $important =0; while () {if (/\[XYZ\]/) {$important = 1;next;}; if (/\[\/XYZ\]/){$important=0;next}; if ($important) {print;}};' importantthing another important thing yet another thing hello! j...@squeeje:~$ how can i sovle this question? what is SOMEPERLMAGIC? are there any perl gurus, that have a little spare time? not a guru... I just love it... perl rules :) joao Thank you! :\ -- To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org Archive: http://lists.debian.org/1294137620.2467.9.ca...@squeeje.critical.pt
Re: a perl question
On Tue, Jan 4, 2011 at 11:40 AM, Joao Ferreira gmail joao.miguel.c.ferre...@gmail.com wrote: On Tue, 2011-01-04 at 02:27 -0800, S Mathias wrote: cat asdf.txt bla-bla bla-bla bla[XYZ] importantthing another important thing [/XYZ] bla-bla bla-bla [XYZ] yet another thing hello! [/XYZ] bla-bla etc. $ SOMEPERLMAGIC asdf.txt output.txt $ cat output.txt importantthing another important thing yet another thing hello! j...@squeeje:~$ cat asdf.txt bla-bla bla-bla bla[XYZ] importantthing another important thing [/XYZ] bla-bla bla-bla [XYZ] yet another thing hello! [/XYZ] bla-bla j...@squeeje:~$ j...@squeeje:~$ j...@squeeje:~$ j...@squeeje:~$ j...@squeeje:~$ cat asdf.txt | perl -e 'my $important =0; while () {if (/\[XYZ\]/) {$important = 1;next;}; if (/\[\/XYZ\]/){$important=0;next}; if ($important) {print;}};' importantthing another important thing yet another thing hello! Or use .. range operator: perl -ne 'print if (/\[XYZ\]/../\[\/XYZ\]/ and not /\[\/?XYZ\]/)' PD: Should I add OT: to subject , or is it not ok doing that when thread is started?? -- To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org Archive: http://lists.debian.org/aanlktikfyl3-jhvchvr56arbh+6qejxssf3y4tpmg...@mail.gmail.com
Re: a perl question
S Mathias smathias1...@yahoo.com wrote: cat asdf.txt bla-bla bla-bla bla[XYZ] importantthing another important thing [/XYZ] bla-bla bla-bla [XYZ] yet another thing hello! [/XYZ] bla-bla etc. $ SOMEPERLMAGIC asdf.txt output.txt $ cat output.txt importantthing another important thing yet another thing hello! how can i sovle this question? what is SOMEPERLMAGIC? are there any perl gurus, that have a little spare time? What are your criteria? Matching important or hello somewhere in the text? Something else? It's really not clear by your example what is to be captured. For example, if it's important or hello then personally I'd use egrep and avoid the complexity of perl entirely: $ egrep 'important|hello' asdf.txt importantthing another important thing yet another thing hello! $ perl -ne '/important|hello/ print' asdf.txt importantthing another important thing yet another thing hello! Chris -- To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org Archive: http://lists.debian.org/dfebv7xbgl@news.roaima.co.uk
tricky perl question - ascending order
or maybe in bash.. script/one liner e.g.: input: http://pastebin.com/raw.php?i=pMZPEsMZ i want to make this output from it: http://pastebin.com/raw.php?i=kH8VxT0A So from the input, i want to make an ascendant order, how many things are under a SOMETHING-XX Does anyone has any perl magic in the pocket, how to do this? :D Thank you very, very much..:\ -- To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org Archive: http://lists.debian.org/1274631338.6474.20.ca...@localhost
Re: tricky perl question - ascending order
Jozsi Vadkan wrote: or maybe in bash.. script/one liner e.g.: input: http://pastebin.com/raw.php?i=pMZPEsMZ i want to make this output from it: http://pastebin.com/raw.php?i=kH8VxT0A So from the input, i want to make an ascendant order, how many things are under a SOMETHING-XX Does anyone has any perl magic in the pocket, how to do this? :D Thank you very, very much..:\ Assuming you can rely on the positions of the blank lines, this seems to work. Should be easy to change if you want to rely on SOMETHING being at the beginning. perl -e '$f=1; while() { chomp; if ($_ eq ) { $f=1 } else { if ($f) { $x{$_}=[]; $k=$_; $f=0 } else { push @{$x{$k}}, $_ } } } for(sort keys %x) { print $_, \n, join(\n, @{$x{$_}}), \n\n }' There's probably a perl hacker or two who can do it neater, but as I say, it seems to work ;) -- Chris Jackson Shadowcat Systems Ltd. -- To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org Archive: http://lists.debian.org/4bf95e41.4020...@shadowcat.co.uk
Re: tricky perl question - ascending order
wow, thanks!! and how exactly can i use this magic? http://pastebin.com/raw.php?i=XZ1rn2bM sorry for the dumb question:\ Thank you! Jozsi Vadkan wrote: or maybe in bash.. script/one liner e.g.: input: http://pastebin.com/raw.php?i=pMZPEsMZ i want to make this output from it: http://pastebin.com/raw.php?i=kH8VxT0A So from the input, i want to make an ascendant order, how many things are under a SOMETHING-XX Does anyone has any perl magic in the pocket, how to do this? :D Thank you very, very much..:\ Assuming you can rely on the positions of the blank lines, this seems to work. Should be easy to change if you want to rely on SOMETHING being at the beginning. perl -e '$f=1; while() { chomp; if ($_ eq ) { $f=1 } else { if ($f) { $x{$_}=[]; $k=$_; $f=0 } else { push @{$x{$k}}, $_ } } } for(sort keys %x) { print $_, \n, join(\n, @{$x{$_}}), \n\n }' There's probably a perl hacker or two who can do it neater, but as I say, it seems to work ;) -- Chris Jackson Shadowcat Systems Ltd. -- To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org Archive: http://lists.debian.org/1274634201.6474.33.ca...@localhost
Re: tricky perl question - ascending order
The solution [from the FreeBSD mailing list]: perl -00 -e 'print map $_-[0], sort { $a-[1] = $b-[1] } map [$_, tr/\n//], ' before.txt after.txt Thank you!! or maybe in bash.. script/one liner e.g.: input: http://pastebin.com/raw.php?i=pMZPEsMZ i want to make this output from it: http://pastebin.com/raw.php?i=kH8VxT0A So from the input, i want to make an ascendant order, how many things are under a SOMETHING-XX Does anyone has any perl magic in the pocket, how to do this? :D Thank you very, very much..:\ -- To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org Archive: http://lists.debian.org/1274647168.6474.48.ca...@localhost
perl question
Hi I have a set of constants setup in my script RC_OK ... ... I use LWP::Simple which also uses RC_OK, and I get a main::RC_OK redifinition is there some way around this with out renaming my constants. Alex signature.asc Description: Digital signature
Re: perl question
Hi, did you check this issue on Perl sites? Try to start with www.cpan.org. BTW this is a very great site. Good luck, Gabor 2009/12/19 Alex Samad a...@samad.com.au: Hi I have a set of constants setup in my script RC_OK ... ... I use LWP::Simple which also uses RC_OK, and I get a main::RC_OK redifinition is there some way around this with out renaming my constants. Alex -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.10 (GNU/Linux) iEYEARECAAYFAkssinMACgkQkZz88chpJ2N9sQCfc4mkgkatwHjCGzKJLGZZla/h oQoAnRP9hOxIzvMjdtqCZi4PriHYKSh7 =KFfZ -END PGP SIGNATURE- -- Linux: Choice of a GNU Generation -- To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Re: perl question
How about setting it a local variable? And I think that you'd better send such a question to a perl mailing list. Alex Samad wrote: Hi I have a set of constants setup in my script RC_OK ... ... I use LWP::Simple which also uses RC_OK, and I get a main::RC_OK redifinition is there some way around this with out renaming my constants. Alex -- To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Re: perl question
On Sat, 19 Dec 2009, Alex Samad wrote: I have a set of constants setup in my script RC_OK ... ... I use LWP::Simple which also uses RC_OK, and I get a main::RC_OK redifinition is there some way around this with out renaming my constants. You can suppress symbol importing, and then call methods the long way: use LWP::Simple qw(); my $html = LWP::Simple::get(http://...;); Or just import what you want: use LWP::Simple qw(get); my $html = get(http://...;); See http://perldoc.perl.org/Exporter.html. cd -- To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Re: perl question
On Sat, Dec 19, 2009 at 11:00:07AM -0500, Chris Dale wrote: On Sat, 19 Dec 2009, Alex Samad wrote: I have a set of constants setup in my script RC_OK ... ... I use LWP::Simple which also uses RC_OK, and I get a main::RC_OK redifinition is there some way around this with out renaming my constants. You can suppress symbol importing, and then call methods the long way: use LWP::Simple qw(); my $html = LWP::Simple::get(http://...;); Or just import what you want: use LWP::Simple qw(get); my $html = get(http://...;); See http://perldoc.perl.org/Exporter.html. thanks for that. Did some more reading and it seems constants don't really have a scope which is why I was having the problem. cd -- More and more of our imports are coming from overseas. - George W. Bush 09/26/2005 On NPR's Morning Edition signature.asc Description: Digital signature
Stumped with a Posix/Perl Question
Given: A - 1 A - 2 B - 1 B - 2 what's the simplest command or perl script to print it as: A (1, 2) B (1, 2) or something equivalent. Thanks -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]
Re: Stumped with a Posix/Perl Question
Moin, * William Ballard wrote (2004-04-02 00:10): Given: A - 1 A - 2 B - 1 B - 2 what's the simplest command or perl script to print it as: A (1, 2) B (1, 2) or something equivalent. Is that an array? Depending on the size and whether it's fixed I would use either printf or something with join. Thorsten -- Once upon the time, the music industry had something to offer to us - they distributed the music we would have never heard without them. Now, they need laws that prevent us to do ourself what they do for money. pgp0.pgp Description: PGP signature
Re: Stumped with a Posix/Perl Question
On Thu, Apr 01, 2004 at 02:10:46PM -0800, William Ballard wrote: Given: A - 1 A - 2 B - 1 B - 2 what's the simplest command or perl script to print it as: A (1, 2) B (1, 2) or something equivalent. Hmm, one of the zillions of ways of doing something equivalent, with the data in file tmp/msg-data: $ perl -nae '{push @{$x{$F[0]}},$F[2]}END{foreach(sort keys %x){print $_ (; print join(, ,@{$x{$_}});print )\n}}' tmp/msg-data A (1, 2) B (1, 2) or perhaps a bit more legibly: #!/usr/bin/perl -w use strict; my %x; while ( DATA ) { chomp; my @F = split; push @{$x{$F[0]}}, $F[2] } foreach ( sort keys %x ) { print $_ (; print join(, ,@{$x{$_}}); print )\n } __END__ A - 1 A - 2 B - 1 B - 2 This builds a hash keyed on the first space-delimited token on a line, with the hash value being an array reference to which the 3rd token is pushed. Afterwards the hash is iterated for printing, and the arrays pretty-printed using join. Ken -- Ken Irving, Research Analyst, [EMAIL PROTECTED], 907-474-6152 Water and Environmental Research Center Institute of Northern Engineering University of Alaska, Fairbanks -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]
Re: perl question
Do not reinvent wheel :). Use standart Perl modules. use File::Path; rmtree([$dir]); See File::Path docs for more info. KGM Correct me if I'm wrong, but this is what the OP *didn't* want to do KGM (taken from File::Path doc): KGM All of the files and directories KGM below each root, as well as the roots themselves, KGM ^^^ KGM will be deleted. Ooops. My fault - I didn't noticed requirement do not touch root itself. -- -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- | Ilya Martynov (http://martynov.org/)| | GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80 E4AE BE1A 53EB 323B DEE6 | | AGAVA Software Company (http://www.agava.com/) | -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Re: perl question
Here's one for some of the perl guys I want to delete a directory that will have files in it... I don't know the name of the files there for wildcards might be needed I understand that rmdir will wipe out an empty directory and unlink will wipe out files (only if I know the names of the files) What would be a nice command to remove a dirtory that had files in it? Even better what would be a nice command to delete all files in one directory... (leaving the directory intact) wt sub emptydir { wt my $dir = shift; wt [..skip..] wt } wt but this code is untested and is likely to cause brain damage wt and multiple scleroses. Do not reinvent wheel :). Use standart Perl modules. use File::Path; rmtree([$dir]); See File::Path docs for more info. -- -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- | Ilya Martynov (http://martynov.org/)| | GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80 E4AE BE1A 53EB 323B DEE6 | | AGAVA Software Company (http://www.agava.com/) | -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Re: perl question
Ilya Martynov wrote: Here's one for some of the perl guys I want to delete a directory that will have files in it... I don't know the name of the files there for wildcards might be needed I understand that rmdir will wipe out an empty directory and unlink will wipe out files (only if I know the names of the files) What would be a nice command to remove a dirtory that had files in it? Even better what would be a nice command to delete all files in one directory... (leaving the directory intact) Do not reinvent wheel :). Use standart Perl modules. use File::Path; rmtree([$dir]); See File::Path docs for more info. Correct me if I'm wrong, but this is what the OP *didn't* want to do (taken from File::Path doc): All of the files and directories below each root, as well as the roots themselves, ^^^ will be deleted.
Re: perl question
From: Mike Egglestone[EMAIL PROTECTED] To: debian-userdebian-user@lists.debian.org Subject: perl question Date: Thu, Jul 18, 2002, 4:53 AM Hello... Here's one for some of the perl guys I want to delete a directory that will have files in it... I don't know the name of the files there for wildcards might be needed I understand that rmdir will wipe out an empty directory and unlink will wipe out files (only if I know the names of the files) What would be a nice command to remove a dirtory that had files in it? Even better what would be a nice command to delete all files in one directory... (leaving the directory intact) sub emptydir { my $dir = shift; opendir DIR,$dir or die canna opendir $dir; my @d = sort grep($_ ne '.' $_ ne '..',readdir DIR); closedir DIR; foreach my $item ( @d ) { my $path = $dir/$item; undef $@; if (-d $path) { emptydir($path); ### eval { rmdir $path; }; } else { eval { unlink $path; }; } warn $@ if $@; } } but this code is untested and is likely to cause brain damage and multiple scleroses. or, just to zap normal files in a known directory, this might work: unlink grep -f,$dir/*; and then again it might not. -- DEBIAN NEWBIE TIP #7 from Will Trillich [EMAIL PROTECTED] : Wondering what COMMANDS you have at your disposal? Try pressing the TAB key at the command line. For example, aptTAB will show you all the commands that start with apt. (This is called completion if you want to look it up in your shell's manpage.) (Different implementions have the TAB completion set up differently -- you may need to press TAB twice.) Also see http://newbieDoc.sourceForge.net/ ...
Perl Question Recap
Mike's Question: I want to delete a directory that will have files in it...I don't know the name of the files there for wildcards might be needed I understand that rmdir will wipe out an empty directoryand unlink will wipe out files (only if I know the names of the files) What would be a nice command to remove a dirtory that had files in it? Even better what would be a nice command to delete all files in one directory... (leaving the directory intact) ---From Lamer: Simply Speaking, This would have been done better with these shell commands: # cd /directory # rm -rf * # cd ..; --- From Joost: #!/usr/bin/perl -w use File::Path; rmtree(some/dir, 0, 1); =pod man File::Path =cut ---From Craig: to remove a dirtory that had files in it: - rm -rf directory to delete all files in one directory (leaving the directory intact) - rm -rf directory/* to delete everything in a directory, including subdirectories - find . -type f | xargs rm -f to delete all files in a directory or its subdirectories, but keep the directory structure intact. Perl isn't required. ---From Bud: Even better what would be a nice command to delete all filesin one directory... (leaving the directory intact) #! /usr/bin/perl -w $dir = /path/to/dir; opendir(DIR, $dir) or die can't opendir $dir: $!; while ( defined ($file = readdir DIR) ) { next if $file =~ /^\.\.?$/; # skip . and .. unlink $file; } Quick and dirty, but I think it will delete all files in one directory. Won't handle subdirs. Then you could probably just close(DIR); rmdir $dir; to get rid of the directory. --- From Larry Wall: There's more than one way to do things A fine example of life imitating art ;-) Scott Hamma __ Do You Yahoo!? Get personalized email addresses from Yahoo! Mail http://personal.mail.yahoo.com/
Re: perl question
On Tue, 17 Jul 2001, Craig Dickson wrote: What would be a nice command to remove a dirtory that had files in it? rm -rf directory But if you don't want to spawn a sh. Check all this as it is off the cuff and I would usually use backticks or system to do this type of thing. #!/usr/bin/perl -w use strict; use File:Path; rmtree(/);# always be prepared Even better what would be a nice command to delete all files in one directory... (leaving the directory intact) This is a vague question, so you get various answers. Are subdirectories files? Are hidden files to be counted? Are files in subdirectories in the directory? What about lost+found subdirectories? rm -rf directory/* This is shell to remove all unhidden entries in a directory and all their contents. Leaves the .files in directory. The perl is: #!/usr/bin/perl -w use strict; use File:Path; my @list = directory/*; foreach my $en (@list) { unlink $en if not -d $en; rmtree($en) if -d $en; } which will delete everything in a directory, including subdirectories; or find . -type f | xargs rm -f This removes all the regular files in . and in its subdirectories. #!/usr/bin/perl -w use strict; use File:Find; find( sub { unlink @_[0] if -f @_[0] }, directory): This would remove everything but directories. find( sub { unlink @_[0] if not -d @_[0] }, directory): to delete all files in a directory or its subdirectories, but keep the directory structure intact. Perl isn't required. My treatment here is naive, but hopefully brings some of the issues to light. Look at the boot scripts under /etc which clean out /tmp, to get an idea of some of the issues to consider. -- rob Live the dream.
Re: Perl Question Recap
thanks for all the inputs !!! I ended up using the rmtree command... I needed to execute this in Perl because I have a web based emailer written in Perl... One part of the program will create an upload directory for the user ... however... I couldn't get a quota on it so I just delete the directory and re-create it when they log in. thus they can't upload a million files and take up hard disk space... (well, I suppose they could for one session...) Anyway... I'm really new to Perl and I'm guessing that I can't run shell commands within a perl script... thanks Mike The following message was sent by Hamma Scott [EMAIL PROTECTED] on Wed, 18 Jul 2001 04:41:29 -0700 (PDT). Mike's Question: I want to delete a directory that will have files in it...I don't know the name of the files there for wildcards might be needed I understand that rmdir will wipe out an empty directoryand unlink will wipe out files (only if I know the names of the files) What would be a nice command to remove a dirtory that had files in it? Even better what would be a nice command to delete all files in one directory... (leaving the directory intact) ---From Lamer: Simply Speaking, This would have been done better with these shell commands: # cd /directory # rm -rf * # cd ..; --- From Joost: #!/usr/bin/perl -w use File::Path; rmtree(some/dir, 0, 1); =pod man File::Path =cut ---From Craig: to remove a dirtory that had files in it: - rm -rf directory to delete all files in one directory (leaving the directory intact) - rm -rf directory/* to delete everything in a directory, including subdirectories - find . -type f | xargs rm -f to delete all files in a directory or its subdirectories, but keep the directory structure intact. Perl isn't required. ---From Bud: Even better what would be a nice command to delete all filesin one directory... (leaving the directory intact) #! /usr/bin/perl -w $dir = /path/to/dir; opendir(DIR, $dir) or die can't opendir $dir: $!; while ( defined ($file = readdir DIR) ) { next if $file =~ /^\.\.?$/; # skip . and .. unlink $file; } Quick and dirty, but I think it will delete all files in one directory. Won't handle subdirs. Then you could probably just close(DIR); rmdir $dir; to get rid of the directory. --- From Larry Wall: There's more than one way to do things A fine example of life imitating art ;-) Scott Hamma __ Do You Yahoo!? Get personalized email addresses from Yahoo! Mail http://personal.mail.yahoo.com/ -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]
Re: Perl Question Recap
--- Mike Egglestone [EMAIL PROTECTED] wrote: thanks for all the inputs !!! Just condensing all the answers given (more for myself) I'm really new to Perl and I'm guessing that I can't run shell commands within a perl script... Check out system() and exec()... __ Do You Yahoo!? Get personalized email addresses from Yahoo! Mail http://personal.mail.yahoo.com/
perl question
Hello... Here's one for some of the perl guys I want to delete a directory that will have files in it... I don't know the name of the files there for wildcards might be needed I understand that rmdir will wipe out an empty directory and unlink will wipe out files (only if I know the names of the files) What would be a nice command to remove a dirtory that had files in it? Even better what would be a nice command to delete all files in one directory... (leaving the directory intact) Thanks Mike
Re: perl question
Mike Egglestone wrote: What would be a nice command to remove a dirtory that had files in it? rm -rf directory Even better what would be a nice command to delete all files in one directory... (leaving the directory intact) rm -rf directory/* which will delete everything in a directory, including subdirectories; or find . -type f | xargs rm -f to delete all files in a directory or its subdirectories, but keep the directory structure intact. Perl isn't required. Craig
Re: perl question
On Wednesday 17 July 2002 03:53 pm, Mike Egglestone wrote: Hello... Here's one for some of the perl guys I want to delete a directory that will have files in it... I don't know the name of the files there for wildcards might be needed I understand that rmdir will wipe out an empty directory and unlink will wipe out files (only if I know the names of the files) What would be a nice command to remove a dirtory that had files in it? Even better what would be a nice command to delete all files in one directory... (leaving the directory intact) #! /usr/bin/perl -w $dir = /path/to/dir; opendir(DIR, $dir) or die can't opendir $dir: $!; while ( defined ($file = readdir DIR) ) { next if $file =~ /^\.\.?$/; # skip . and .. unlink $file; } Quick and dirty, but I think it will delete all files in one directory. Won't handle subdirs. Then you could probably just close(DIR); rmdir $dir; to get rid of the directory. -- Bud Rogers [EMAIL PROTECTED] http://www.sirinet.net/~budr All things in moderation. And not too much moderation either.
Re: perl question
On Wed, Jul 17, 2002 at 04:53:50PM -0400, Mike Egglestone wrote: What would be a nice command to remove a dirtory that had files in it? Even better what would be a nice command to delete all files in one directory... (leaving the directory intact) #!/usr/bin/perl -w use File::Path; rmtree(some/dir, 0, 1); =pod man File::Path =cut Cheers, Joost
Re: perl question
Simply Speaking, This would have been done better with these shell commands: # cd /directory # rm -rf * # cd ..; :) rgrds, Calvin Lamer -- From: Mike Egglestone[EMAIL PROTECTED] To: debian-userdebian-user@lists.debian.org Subject: perl question Date: Thu, Jul 18, 2002, 4:53 AM Hello... Here's one for some of the perl guys I want to delete a directory that will have files in it... I don't know the name of the files there for wildcards might be needed I understand that rmdir will wipe out an empty directory and unlink will wipe out files (only if I know the names of the files) What would be a nice command to remove a dirtory that had files in it? Even better what would be a nice command to delete all files in one directory... (leaving the directory intact) Thanks Mike -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]
ssl and libwww-perl question
libwww-perl supports ssl out of the box _kinda_ if Crypt::SSLeay is installed (or so the readme would have me believe). I dug around in dselect a bit and find only Net::SSLeay (which the doc says is better, but not compatible). The question is if anyone out there knows how to set debian packages up to make this work, or if I am resigned to grabbing/building source (which I will start promptly, but would rather not worry about maintaining). Thanks in advance! Jonathan -- [EMAIL PROTECTED] GPG public key available from http://lupavista.jamdata.net/gpg.asc -- Lament 1750: If I only had a radioactive decay source and a fast free-running oscillator... pgpxyhNwEq8om.pgp Description: PGP signature
another perl question
Hi, can anyone tell me why there are perl5 binaries and perl-5 binaries in /usr/bin ? Whats the differemce ? -david -- =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Remember, you are unique ... just like everyone else. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Re: another perl question
david sowerby [EMAIL PROTECTED] wrote: Hi, can anyone tell me why there are perl5 binaries and perl-5 binaries in /usr/bin ? Whats the differemce ? None: they're hard links to each other, provided for convenience. [EMAIL PROTECTED] ~]$ ls -i1 /usr/bin/perl{-5.005,5*} 2275 /usr/bin/perl-5.005 2275 /usr/bin/perl5.005 2275 /usr/bin/perl5.00503 You're best off using /usr/bin/perl instead, though (which should always link through the alternatives system to a useful version). -- Colin Watson [EMAIL PROTECTED]
(hopefully) simple perl question...
Is there a built in command, or shell command to retrieve the process name from a pid? The best I could come up with is slurping the stuff from /proc/cmdline or something like ps|cut, but it seems to me there is probably a better way I am ignorant of. Thanks! Jonathan -- [EMAIL PROTECTED] GPG public key available from http://www.jamdata.net/~jjlupa/gpg.asc pgpMvkrEdfWIR.pgp Description: PGP signature
Re: (hopefully) simple perl question...
On Mon, 28 Feb 2000, Jonathan Lupa wrote: Is there a built in command, or shell command to retrieve the process name from a pid? ps ax | awk '$1 == pid {print $5}' There's no builtin command to do this. I don't know if Perl can do it or not. I doubt it, though. The best I could come up with is slurping the stuff from /proc/cmdline or something like ps|cut, but it seems to me there is probably a better way I am ignorant of. /proc/pid/cmdline won't work on anything except linux; you should use ps.
Re: (hopefully) simple perl question...
[EMAIL PROTECTED] (William T Wilson) wrote: On Mon, 28 Feb 2000, Jonathan Lupa wrote: Is there a built in command, or shell command to retrieve the process name from a pid? ps ax | awk '$1 == pid {print $5}' Or indeed 'ps -o%c h -p pid'. This will probably break on other Unices (and older versions of ps, for that matter), but this is debian-user, right? :) -- Colin Watson [EMAIL PROTECTED]
Re: (hopefully) simple perl question...
On Tue, Feb 29, 2000 at 03:42:20AM +, Colin Watson wrote: [EMAIL PROTECTED] (William T Wilson) wrote: ps ax | awk '$1 == pid {print $5}' Or indeed 'ps -o%c h -p pid'. Thanks guys! :) -- [EMAIL PROTECTED] GPG public key available from http://www.jamdata.net/~jjlupa/gpg.asc pgp5px2HKScTJ.pgp Description: PGP signature
Re: (hopefully) simple perl question...
Jonathan Lupa wrote: Is there a built in command, or shell command to retrieve the process name from a pid? The best I could come up with is slurping the stuff from /proc/cmdline or something like ps|cut, but it seems to me there is probably a better way I am ignorant of. I wonder if the Proc::ProcessTable module, available at CPAN, wouldn't do this for you?
Re: offtopic: perl question about dialog.pl
What you'all don't count from zero? Okay, add one then... -- ++ | Eric G. Milleregm2@jps.net | | GnuPG public key: http://www.jps.net/egm2/gpg.asc | ++
offtopic: perl question about dialog.pl
Hello, I'm new to perl and want to write a small perl script with a nice userinterface. There is a wrapperscript for /usr/bin/dialog, but it gives the following warning: Use of implicit split to @_ is deprecated at ./dialog.pl line 34. I'm using potato with perl-5.005. What is the correct syntax in dialog.pl for split()? Thanks, -- Olaf I used the following small testscript: --- #!/usr/bin/perl -w require dialog.pl; rhs_msgbox(Title,Just a message.,30); --- Portion of /usr/lib/perl5/dialog.pl: --- sub rhs_msgbox { local ( $title, $message, $width ) = @_; local ( $tmp, $height, $message_len ); $message = rhs_wordwrap($message, $width); $message_len = split(/^/, $message);# -- line 34 $tmp = $message; if (chop($tmp) eq \n) { $message_len++; } $height = 4 + $message_len; $tmp = system(dialog --title \$title\ --msgbox \$message\ $height $width); if ($tmp) { return 0; } else { return 1; } } ---
Re: offtopic: perl question about dialog.pl
Olaf Conradi ([EMAIL PROTECTED]) wrote: Use of implicit split to @_ is deprecated at ./dialog.pl line 34. $message_len = split(/^/, $message);# -- line 34 Split normally returns an array, not a scalar... unless I'm missing something. (I'm no perl guru.) -- Greg Wooledge| Truth belongs to everybody. [EMAIL PROTECTED] | Red Hot Chili Peppers, http://www.kellnet.com/wooledge/ | pgpnd4XN1ytjt.pgp Description: PGP signature
Re: offtopic: perl question about dialog.pl
-BEGIN PGP SIGNED MESSAGE- On Mon, 25 Oct 1999, Olaf Conradi wrote: Use of implicit split to @_ is deprecated at ./dialog.pl line 34. $message_len = split(/^/, $message);# -- line 34 split always splits to an array. Here, you're trying to get the number of elements generated by the split call, so it implicitly splits to the @_ array. This is depreciated. One way to get the same effect would be to use the s/// funtion something like this: $message_len = $message=~s/^/^/mog; There may be other ways. Those other ways may even be better. - -- finger for PGP public key. -BEGIN PGP SIGNATURE- Version: 2.6.3ia Charset: noconv iQCVAwUBOBPiNr7M/9WKZLW5AQGe6wQAo3DIzrc4An6A2AYMQ68T+KuJmS4oT7kr iHPgHpkfWDmnqh127QohHs0Ch/3u+60j3HnAEOMJbNPT1Blybc4g4Mfc2T6rhmHo ExQnAxgMM8J8vjYjfST/IlbfTKwjXyo3LNqXldsdojI2RLXXZzxFzchyxTW53oBn 0sE8umh8ceQ= =JnCc -END PGP SIGNATURE-
Re: offtopic: perl question about dialog.pl
For a count of elements in an array $count = $#array; -- ++ | Eric G. Milleregm2@jps.net | | GnuPG public key: http://www.jps.net/egm2/gpg.asc | ++
Re: offtopic: perl question about dialog.pl
On Sun, 24 Oct 1999, Eric G . Miller wrote: For a count of elements in an array $count = $#array; ^ this is the subscript of the last element in array, one less than the length, since there is a 0th element; $count++; # number of elements in array @array; you could also do: $count = scalar(@array); []s, Mario O.de MenezesMany are the plans in a man's heart, but IPEN-CNEN/SP is the Lord's purpose that prevails http://curiango.ipen.br/~mario Prov. 19.21 http://www.revistalinux.com.br
Re: #!/Perl question
Quoting Manoj Srivastava ([EMAIL PROTECTED]): Hi, Joey == Joey Hess [EMAIL PROTECTED] writes: The following works under more shells (and also is a man page ;-) #!/usr/bin/perl -- # -*- Mode: Perl -*- # 'di'; 'ig00'; true || eval 'exec perl -S $0 $argv:q'; eval '(exit $?0)' eval 'exec perl -S $0 ${1+$@}' eval 'exec perl -S $0 $argv:q' if $running_under_some_shell; Joey Yes, but it doesn't address the orginial problem: It will fail if perl is Joey not in /usr/bin. Well. Just get rid of the #! line, and it works as expected (I really shouyld have caught that). See, if not invoked under Perl, the first two lines are shell no-ops, and the third line execs Perl. I still use parts of the template. I remember seeing a program that was legel in 7 languages ... Nice, but you're all more fortunate than me! ~$ uname -a SunOS tyne 5.4 Generic_101945-61 sun4m sparc ~$ which perl /usr/bin/perl ~$ cd /usr/bin /usr/bin$ ls -l perl* lrwxrwxrwx 1 root other 19 Feb 22 1996 perl - /usr/local/bin/perl /usr/bin$ cd /usr/local/bin /usr/local/bin$ ls -l perl* lrwxrwxrwx 1 root other 9 Jun 20 1997 perl - perl4.036 === -rwxr-xr-x 1 root other 339420 Dec 15 1995 perl4.036 lrwxrwxrwx 1 root other 11 Jun 20 1997 perl5 - perl5.00401 -rwxr-xr-x 1 root other 545656 Feb 23 1996 perl5.002 -rwxr-xr-x 1 root other 617948 Jun 20 1997 perl5.00401 -rwxr-xr-x 1 root other 25020 Jun 20 1997 perlbug -rwxr-xr-x 1 root other 11215 Jun 20 1997 perldoc Cheers, -- Email: [EMAIL PROTECTED] Tel: +44 1908 653 739 Fax: +44 1908 655 151 Snail: David Wright, Earth Science Dept., Milton Keynes, England, MK7 6AA Disclaimer: These addresses are only for reaching me, and do not signify official stationery. Views expressed here are either my own or plagiarised.
Re: #!/Perl question
Hi, Joey == Joey Hess [EMAIL PROTECTED] writes: The following works under more shells (and also is a man page ;-) #!/usr/bin/perl -- # -*- Mode: Perl -*- # 'di'; 'ig00'; true || eval 'exec perl -S $0 $argv:q'; eval '(exit $?0)' eval 'exec perl -S $0 ${1+$@}' eval 'exec perl -S $0 $argv:q' if $running_under_some_shell; Joey Yes, but it doesn't address the orginial problem: It will fail if perl is Joey not in /usr/bin. Well. Just get rid of the #! line, and it works as expected (I really shouyld have caught that). See, if not invoked under Perl, the first two lines are shell no-ops, and the third line execs Perl. I still use parts of the template. I remember seeing a program that was legel in 7 languages ... manoj -- In anticipation of 2.10.02 release, updated to patchlevel +ircu2.10.01+.config6-7.config7-8.lgline3.iwho.limit.glibc.motdcache2.trace.whois1-2.config8-9.statsw.sprintf2-3.msgtree2.memleak1-2+.msgtree2-3.gline8-9.gline9-10.invite2.rbr.stats.numclients.whisper.whisper1-2.stats1-2.nokick1-2.chroot.config9-11.snomask7-8.limi+t1-3.userip1-3.userip3-4.config11-12.config12-13.umode2-3.akillsbt.who4-5.kn.kn1-2.freebsdcore2.msgtree3-5.y2k.glibc1-2.rmfunc.msgf+lags2.who5-6.nickchange2.glibc2-3.modeless3 From the annoucement of ircd 2.10.01-3 for Debian GNU/Linux Manoj Srivastava [EMAIL PROTECTED] http://www.debian.org/%7Esrivasta/ Key C7261095 fingerprint = CB D9 F4 12 68 07 E4 05 CC 2D 27 12 1D F5 E8 6E
Re: #!/Perl question
-BEGIN PGP SIGNED MESSAGE- On Thu, 2 Sep 1999, Brian Servis wrote: *- On 2 Sep, Jonathan Markevich wrote about Re: #!/Perl question On Fri, Sep 03, 1999 at 03:04:49AM +0800, Hans van den Boogert wrote: I'm trying to learn some Perl. I found an on-line book which is Unix biased, but the scripts all start with #!/usr/local/bin/perl (which makes sense if you have compiled and installed it yourself). However, on my Debian system Perl was of course put in /usr/bin/perl. So how can I write a Perl script that be executed on a variety of systems (Unix/Linux/DOS)?? Personally, I would count on /usr/bin/perl. It seems unusual to take such an important key to lots of system-based scripts and keep it local. Check out this: I think(i.e. just my local experience) many of the commercial Unix's put everything under /usr/local that is not part of the core OS. Unlike Linux distributions most commercial Unix's don't come with all the apps pre-packaged. One solution would be to write a makefile that detects the location of the perl binary and then prepends the proper shebang line to the beginning of your perl programs. - -- finger for PGP public key. -BEGIN PGP SIGNATURE- Version: 2.6.3ia Charset: noconv iQCVAwUBN88YXr7M/9WKZLW5AQGmMAP/SjX8U3wyIWTQDZNy1twrlGP20LKq51c7 ayJTppyfV56sps2qdPOh+kclL0FnMqzWCJaISNtwRicYeMLAIb6CGjeQedgV6Vgz NJh3vHDYWnXU14QX3DX60xANOLOmp+3mCER5SvaNcLNFJyyYEXUzJDe3IoUbr6nN +mIVd1UFHF0= =2YGA -END PGP SIGNATURE-
Re: #!/Perl question
Hans van den Boogert wrote: I'm trying to learn some Perl. I found an on-line book which is Unix biased, but the scripts all start with #!/usr/local/bin/perl (which makes sense if you have compiled and installed it yourself). However, on my Debian system Perl was of course put in /usr/bin/perl. So how can I write a Perl script that be executed on a variety of systems (Unix/Linux/DOS)?? This will work no matter where your perl executable is. Won't work under dos though, probably. Note the perl script doesn't start with any #! at all, and is first run as a shell script (the kernel knows where the shell is, and runs it), then as a perl script (the shell has perl on it's path, and runs it). eval 'exec perl -S $0 ${1+$@}' if 0; print hello, world\n; # More perl code here -- see shy jo
Re: #!/Perl question
* Hans van den Boogert [EMAIL PROTECTED] writes: I'm trying to learn some Perl. I found an on-line book which is Unix biased, but the scripts all start with #!/usr/local/bin/perl (which makes sense if you have compiled and installed it yourself). However, on my Debian system Perl was of course put in /usr/bin/perl. So how can I write a Perl script that be executed on a variety of systems (Unix/Linux/DOS)?? Basically form the camel book: eval '(exit $?0)' eval 'exec perl -S $0 ${1+$@}' eval 'exec perl -S $0 $ argv:q' if 0; HTH, Colin -- Colin Marquardt [EMAIL PROTECTED]
Re: #!/Perl question
Brad writes: One solution would be to write a makefile that detects the location of the perl binary and then prepends the proper shebang line to the beginning of your perl programs. Another trick is this: #! /usr/bin/env perl print Hello, world\n; This depends on env being in /usr/bin everywhere, but perhaps that's more widely true than it is of Perl. Personally I just use `#! /usr/bin/perl'. ttfn/rjk
Re: #!/Perl question
On 3 Sep, Hans van den Boogert wrote: I'm trying to learn some Perl. I found an on-line book which is Unix biased, but the scripts all start with #!/usr/local/bin/perl (which makes sense if you have compiled and installed it yourself). However, on my Debian system Perl was of course put in /usr/bin/perl. So how can I write a Perl script that be executed on a variety of systems (Unix/Linux/DOS)?? -- a somebody who last programmed in BASIC back in '84. (Please don't laugh. I was young and my teacher made me to). One can usually be reasonably sure (at least more certain than of the location of the perl executable...) that /bin/sh exists... That is if you're on a Unix system (yes, I count Linux as Unix,tho it ain't Unix (tm) (if it walks like a duck etc...)) Use this incantation at the top of your files instead (will start the file as a sh-script that starts perl (as found by the PATH-variable) on the file itself... #!/bin/sh #! -*-perl-*- eval 'exec perl -x -S $0 ${1:$@}' if 0; To automatically start start perl scripts on a WinDOS machine you usually connect the file suffix you use (.pl) with the Perl interpreter (dunno exactly how) AFAIK there's no support for the hashbang line. You can also run a little script on your perl scripts that transforms them into a .bat (IIRC) file that can be run from anywhere. Will be interesting to see what happens with Windows new scripting host (if that was what it was called (teflon coated memory...:-)) On a pure DOS system? I have no idea... Could probably do the conversion to .bat routine described above... On a Mac you save the scripts as either a droplet or a freestanding exe (big) from the MacPerl application (supports the hashbang line as far as it reads the switches set there) HTH, /Michael -- | Linux: Turn on...Tune in...Fork out... | | Michael Tempsch, member of Ballistic Wizards, TIP#088, POG#130, PPIG#11 | | [EMAIL PROTECTED]|hotmail.com] [EMAIL PROTECTED] | | Cell.Phone:+46 705487554 URL:http://www.dtek.chalmers.se/%7Ed1temp |
Re: #!/Perl question
Hi, Joey == Joey Hess [EMAIL PROTECTED] writes: Joey eval 'exec perl -S $0 ${1+$@}' Joey if 0; The following works under more shells (and also is a man page ;-) I used to use this as a template perl script with built in man page (this was before we had POD and pod2man). This is obsolete, but still interestin in that this is a legal sehll, perl, and nroff script. manoj -- #!/usr/bin/perl -- # -*- Mode: Perl -*- # 'di'; 'ig00'; true || eval 'exec perl -S $0 $argv:q'; eval '(exit $?0)' eval 'exec perl -S $0 ${1+$@}' eval 'exec perl -S $0 $argv:q' if $running_under_some_shell; $ENV{'PATH'} = '.:/usr/users2/pilgrim/srivasta/bin:/usr/local/bin:' . '/usr/bin/X11:/usr/local/lib/perl/scripts:/usr/local/etc:' . '/usr/local/emacs/etc:/proj/bin:/usr/new:/usr/ucb:/bin:' . '/usr/bin:/usr/etc:/etc:/usr/games:/usr/hosts'; ($MYNAME = $0) =~ s|.*/||; $RCSHEADER = '$Header$';#' '$Revision$' =~ /^\$\w+:\s+([.1234567890]+)\s+\$$/;#' $VERSION = $1; # Synopsis: $Usage = END_OF_USAGE; usage: $MYNAME [-h --help] This message END_OF_USAGE ; # BEGIN parse options # [SNIP] # END main # # These next few lines are legal in both Perl and Nroff. .00;# finish .ig 'di \ finish diversion--previous line must be blank .nr nl 0-1 \ fake up transition to first page again .nr % 0 \ start at page 1 '; __END__ From here on it's a standard manual page .TH ADD_RCSID 1 Thu Dec 8 1994 Project Pilgrim, University of Massachusetts at Amherst .SH NAME add_rcsid \- Adds an static constant variable holding the rcs id .SH SYNOPSIS .SH DESCRIPTION .SH OPTIONS .SH ENVIRONMENT .SH EXAMPLES .SH FILES .SH AUTHOR Manoj Srivastava Dec .SH SEE ALSO .SH DIAGNOSTICS .SH BUGS -- Hackers of the world, unite! Manoj Srivastava [EMAIL PROTECTED] http://www.debian.org/%7Esrivasta/ Key C7261095 fingerprint = CB D9 F4 12 68 07 E4 05 CC 2D 27 12 1D F5 E8 6E
Re: #!/Perl question
Manoj Srivastava wrote: Joey eval 'exec perl -S $0 ${1+$@}' Joey if 0; The following works under more shells (and also is a man page ;-) #!/usr/bin/perl -- # -*- Mode: Perl -*- # Yes, but it doesn't address the orginial problem: It will fail if perl is not in /usr/bin. Still a truly frightning script. Thank goodness we have pod now. :-) -- see shy jo
#!/Perl question
I'm trying to learn some Perl. I found an on-line book which is Unix biased, but the scripts all start with #!/usr/local/bin/perl (which makes sense if you have compiled and installed it yourself). However, on my Debian system Perl was of course put in /usr/bin/perl. So how can I write a Perl script that be executed on a variety of systems (Unix/Linux/DOS)?? -- a somebody who last programmed in BASIC back in '84. (Please don't laugh. I was young and my teacher made me to).
Re: #!/Perl question
On Fri, Sep 03, 1999 at 03:04:49AM +0800, Hans van den Boogert wrote: I'm trying to learn some Perl. I found an on-line book which is Unix biased, but the scripts all start with #!/usr/local/bin/perl (which makes sense if you have compiled and installed it yourself). However, on my Debian system Perl was of course put in /usr/bin/perl. So how can I write a Perl script that be executed on a variety of systems (Unix/Linux/DOS)?? Personally, I would count on /usr/bin/perl. It seems unusual to take such an important key to lots of system-based scripts and keep it local. Check out this: file /usr/bin/* | grep perl That should also give you good sample code :) I highly recommend the O'Reilly Camel book. Ain't nothing better. -- a somebody who last programmed in BASIC back in '84. (Please don't laugh. I was young and my teacher made me to). Ahh, I was programming BASIC in '84. Commodore BASIC. Back when it was all upper case... Ah for the old days when joystick programming wasn't that tough... -- Jonathan Markevich [EMAIL PROTECTED] http://members.xoom.com/JMarkevich If everything is coming your way then you're in the wrong lane.
Re: #!/Perl question
*- On 2 Sep, Jonathan Markevich wrote about Re: #!/Perl question On Fri, Sep 03, 1999 at 03:04:49AM +0800, Hans van den Boogert wrote: I'm trying to learn some Perl. I found an on-line book which is Unix biased, but the scripts all start with #!/usr/local/bin/perl (which makes sense if you have compiled and installed it yourself). However, on my Debian system Perl was of course put in /usr/bin/perl. So how can I write a Perl script that be executed on a variety of systems (Unix/Linux/DOS)?? Personally, I would count on /usr/bin/perl. It seems unusual to take such an important key to lots of system-based scripts and keep it local. Check out this: I think(i.e. just my local experience) many of the commercial Unix's put everything under /usr/local that is not part of the core OS. Unlike Linux distributions most commercial Unix's don't come with all the apps pre-packaged. From the university server here: [EMAIL PROTECTED]uname -a SunOS widget.ecn.purdue.edu 5.6 Generic_105181-15 sun4u sparc SUNW,Ultra-4 [EMAIL PROTECTED]which perl /usr/local/bin/perl -- Brian - Mechanical Engineering [EMAIL PROTECTED] Purdue University http://www.ecn.purdue.edu/~servis -
perl question
Hi, I want to use perl to display a list a directories in the tree format, so that I can display them on the web. What is the best way to do it. Later on, I want to make the users be able to click on these tree nodes and to be able to set the permission on each directory. Thanks for any help in advance. Shao. -- Shao Zhang - Running Debian 2.1 ___ _ _ Department of Communications/ __| |_ __ _ ___ |_ / |_ __ _ _ _ __ _ University of New South Wales \__ \ ' \/ _` / _ \ / /| ' \/ _` | ' \/ _` | Sydney, Australia |___/_||_\__,_\___/ /___|_||_\__,_|_||_\__, | Email: [EMAIL PROTECTED] |___/ _
simple perl question
In a perl script i need to load a variable ($CurrentTime) with the systems current time. Normally I would consult with my reference books but am not able to get to them. I find myself using them when I need to work in perl which is not very often... I'm looking for time_stamp something like 07/17/98 14:42:09 for a requirement that has surfaced. I thought maybe something like: $CurrentTime=exec`date +%D %T`; print $CurrentTime; Hope that jibberish above made sense :-/ Oh yeah... The perl version is rather old (v. 4.0.1.8). upgrading is not an option for those solutions requiring version 5.x. Thanks for any help. Please reply to [EMAIL PROTECTED] and the group... -- Unsubscribe? mail -s unsubscribe [EMAIL PROTECTED] /dev/null
Re: simple perl question
I thought maybe something like: $CurrentTime=exec`date +%D %T`; print $CurrentTime; $CurrentTime=localtime(time); Alex Y. -- _ _( )_ ( (o___ +---+ | _ 7 |Alexander Yukhimets| \()| http://pages.nyu.edu/~aqy6633/ | / \ \ +---+ -- Unsubscribe? mail -s unsubscribe [EMAIL PROTECTED] /dev/null
RE: simple perl question
dave oswald [EMAIL PROTECTED] writes: Normally I would consult with my reference books but am not able to get to them. Or you could just try it! :) I thought maybe something like: $CurrentTime=exec`date +%D %T`; print $CurrentTime; % perl -e '$CurrentTime = `date +%D %T`; print $CurrentTime' 07/17/98 22:10:42 -Jeff * | Jeff Schreiber | System administrators are, of course, | | aka - Spectre | incorruptible. You can offer me any | | [EMAIL PROTECTED] | amount of money. And you can believe | | | me, because I'm always right, and I| | | never lie. | | | (Paul Sand - [EMAIL PROTECTED]) | * -- Unsubscribe? mail -s unsubscribe [EMAIL PROTECTED] /dev/null
Did I answer this perl question correctly?
Hi, Could someone please confirm whether the answer I gave below to a friend about perl is correct? Thanks, Mark. -- Forwarded message -- Date: Thu, 2 Apr 1998 10:49:30 +0930 (CST) From: Mark Phillips [EMAIL PROTECTED] To: Bill Moran [EMAIL PROTECTED] Subject: Perl Dear Bill, I am interested in the library of programs in /usr/lib/perl5/. There seem to be lots of potentially useful things there. How do I get them to work? From what I can tell, these are library packages for use with perl. Just like in LaTeX2e you include packages with the command \usepackage{amstex} etc, with perl you include these packages with the command require 'ftp.pl'; Then you can make use of the functionality these libraries provide. To make use of them, you would have to learn how to program in perl, which from what I hear is an excellent and powerful scripting language. One of these days I might even learn it myself. Does that answer your question? Cheers, Mark. __ _\/___\__/___Mark_Phillips___/ \__/_\__/--\__/[EMAIL PROTECTED]/ \__/HE___\__/--APTAIN/ \__/_\__/--\__/__/ /__To be is to do.__I. Kant___/ \__/__\__/___/ /__To do is to be.__A. Sartre_/ /__I am.God___/ /__Jesus did.___/ -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]
Re: Did I answer this perl question correctly?
Hi, Yes, require 'blah.pl'; is correct. You may also want to look at .pm files and the new use blah; directives. manoj use Module LIST use Module use Module VERSION LIST use VERSION Imports some semantics into the current package from the named module, generally by aliasing certain subroutine or variable names into your package. It is exactly equivalent to BEGIN { require Module; import Module LIST; } except that Module must be a bareword. If the first argument to use is a number, it is treated as a version number instead of a module name. If the version of the Perl interpreter is less than VERSION, then an error message is printed and Perl exits immediately. This is often useful if you need to check the current Perl version before useing library modules which have changed in incompatible ways from older versions of Perl. (We try not to do this more than we have to.) The BEGIN forces the require and import to happen at compile time. The require makes sure the module is loaded into memory if it hasn't been yet. The import is not a builtin--it's just an ordinary static method call into the Module package to tell the module to import the list of features back into the current package. The module can implement its import method any way it likes, though most modules just choose to derive their import method via inheritance from the Exporter class that is defined in the Exporter module. See the Exporter manpage. If no import method can be found then the error is currently silently ignored. This may change to a fatal error in a future version. If you don't want your namespace altered, explicitly supply an empty list: use Module (); That is exactly equivalent to BEGIN { require Module; } If the VERSION argument is present between Module and LIST, then the use will call the VERSION method in class Module with the given version as an argument. The default VERSION method, inherited from the Universal class, croaks if the given version is larger than the value of the variable $Module::VERSION. (Note that there is not a comma after VERSION!) Because this is a wide-open interface, pragmas (compiler directives) are also implemented this way. Currently implemented pragmas are: use integer; use diagnostics; use strict qw(subs vars refs); use subsqw(afunc blurfl); These pseudo-modules import semantics into the current block scope, unlike ordinary modules, which import symbols into the current package (which are effective through the end of the file). There's a corresponding no command that unimports meanings imported by use, i.e., it calls unimport Module LIST instead of import. no integer; no strict 'refs'; If no unimport method can be found the call fails with a fatal error. See the perlmod manpage for a list of standard modules and pragmas. -- Pedantry crams our heads with learned lumber, and takes out our brains to make room for it. -- Colton Manoj Srivastava [EMAIL PROTECTED] http://www.datasync.com/%7Esrivasta/ Key C7261095 fingerprint = CB D9 F4 12 68 07 E4 05 CC 2D 27 12 1D F5 E8 6E -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]
Re: [Off Topic] Dumb Perl Question...
Adam Shand wrote: How do I untaint the glob, or better yet access it so that it's not tainted to start with (if that's possible)? The files I'm accessing are safe as only root can write to them, but I'd like to do this the 'right way'. I can't find anything relevant to this in the docs/web/books (doubtless I'm just looking in the wrong places) and it's starting to get irritating :) perldoc perlsec is your friend! :) Bottom line is that globs are *always* tainted, as is anything that relies on shell processing (csh being how globbing is done). Try using File::Find, that should let you get data in an untainted manner. Stephen --- Normality is a statistical illusion. -- me -- TO UNSUBSCRIBE FROM THIS MAILING LIST: e-mail the word unsubscribe to [EMAIL PROTECTED] . Trouble? e-mail to [EMAIL PROTECTED] .
RE: [Off Topic] Dumb Perl Question...
I don't know the answer to this question, but in your shoes I'd start by re-writing the above as: That (with a couple typo's fixed :) does the trick beautifully! Thanks for the pointer, I figured there had to be a way to do it. Adam. Internet Alaska -- 4050 Lake Otis Adam Shand(v) +1 907 562 4638 Anchorage, Alaska Systems Administrator (f) +1 907 562 1677 - http://larry.earthlight.co.nz --- -- TO UNSUBSCRIBE FROM THIS MAILING LIST: e-mail the word unsubscribe to [EMAIL PROTECTED] . Trouble? e-mail to [EMAIL PROTECTED] .
Re: [Off Topic] Dumb Perl Question...
perldoc perlsec is your friend! :) Bottom line is that globs are *always* tainted, as is anything that relies on shell processing (csh being how globbing is done). Yep, I realise this, but what I didn't have is an alternative. There's lots of info on de-tainting user input, but basically zero and globbing except to say that it's all tainted sigh. Try using File::Find, that should let you get data in an untainted manner. This is however what I needed to know about, and has solved my problem... thanks. Adam. Internet Alaska -- 4050 Lake Otis Adam Shand(v) +1 907 562 4638 Anchorage, Alaska Systems Administrator (f) +1 907 562 1677 - http://larry.earthlight.co.nz --- -- TO UNSUBSCRIBE FROM THIS MAILING LIST: e-mail the word unsubscribe to [EMAIL PROTECTED] . Trouble? e-mail to [EMAIL PROTECTED] .
[Off Topic] Dumb Perl Question...
Howdy... Sorry for this stupid question but I'm hoping someone can shed some light, and I'm a 'Perl Beginner'... I'm writing a suid perl script which needs to search through a whole bunch of files in a directory and return some information. It all works fine except that the tainting doesn't like me. It complains with the error: Insecure dependency in glob while running with -T switch at /dev/fd/3 line 22. And the relating lines are: while (/usr/local/lpac/*9j8) { search_lpac($_); } How do I untaint the glob, or better yet access it so that it's not tainted to start with (if that's possible)? The files I'm accessing are safe as only root can write to them, but I'd like to do this the 'right way'. I can't find anything relevant to this in the docs/web/books (doubtless I'm just looking in the wrong places) and it's starting to get irritating :) Any help much appreciated, Thanks, Adam. -- TO UNSUBSCRIBE FROM THIS MAILING LIST: e-mail the word unsubscribe to [EMAIL PROTECTED] . Trouble? e-mail to [EMAIL PROTECTED] .