TCLUG Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [TCLUG:18790] quick way to strip spaces...
> Would it be better at this point to actually make a perl script to do it
> all, instead of just continuously typing in that long line of code again and
> again(say once every week or so...)
A Perl script is just a matter of saving your long line of code to a file,
preferably in a more readable form.
perl -e 'opendir D, "."; for(readdir D) {$x=$_; s/[(,)]/_/g; rename $x, $_;}'
I.e., something more like:
#!/usr/bin/perl
#
opendir D, ".";
for(readdir D){
$x=$_;
s/[(,)]/_/g;
rename $x, $_;
}
Then if you name it myscript.pl, you can call it as
perl myscript.pl
From there you will probably make it more convenient for reuse.
Others have recommended books; my suggestion is O'Reilly's "Learning Perl"
and "Mastering Regular Expressions". If you want a head start, look at the
current issue of Maximum Linux magazine, which has a surprisingly nice
perl intro article.
Andy