Click here to get back home

how to process each directory

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
how to process each directory monk 02-27-2008
Get Chitika Premium
Posted by Jim Gibson on February 27, 2008, 5:16 pm
Please log in for more thread options
In article

> I get from the shell:
>
> << is not a directory.r/logs

The above output line is a clue.

> what the hell?...No such file or directory
>
> Then I do a manual regular cd command to the directory logs and I'm
> in.
> Even with the full path which the program itself printed with print "$_
> \n";
>
> any clues?

Yes. Your output starts with '<<'. Where is the '>>$_' part of your
line? And why do you have '.r/logs' at the end of the line that isn't
in the original print statement?

Maybe you have an embedded \r character in your file? Or some other
unprintable character. On *nix, use 'od -c' to see just what characters
are in your file. Try using a string value or array in your program
instead of reading an external file to ensure you can actually open the
directory with opendir.

If that isn't it, please post a short, complete program (with 'use
strict;' and 'use warnings;') that demonstrates your problem. Use the
special <DATA> filehandle and include your data file at the end of your
program after the line

__DATA__

Also please observe the other guidelines for posting to
comp.lang.perl.misc:
<http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html>
(currently not accessible to me) and posted here twice a week.

Also note that many of the most helpful people reading this newsgroup
are not using Google Groups as a newsreader, so it helps to include the
lines of code to which you are referring.

Good luck!

--
Jim Gibson

Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com

Posted by monk on February 27, 2008, 6:23 pm
Please log in for more thread options
Thanks for the tip 'od -c <filename>'

I uncovered an extra character was being added somehow when slurping
the config file.
I added one little line to my code and now it works like a charm.

foreach (@directories_to_clean){
chomp;

chop; # one extra line that solved my problem.

print "$_\n";

#and everything else is the same

}

Thanks everybody again.



Posted by Jim Gibson on February 27, 2008, 6:51 pm
Please log in for more thread options
In article

> Thanks for the tip 'od -c <filename>'
>
> I uncovered an extra character was being added somehow when slurping
> the config file.
> I added one little line to my code and now it works like a charm.
>
> foreach (@directories_to_clean){
> chomp;
>
> chop; # one extra line that solved my problem.
>
> print "$_\n";
>
> #and everything else is the same
>
> }

That is not a good, long-term solution. It is not likely that slurping
the file is adding extra characters. It is more likely that the file
does not have the proper line endings for your system. As soon as
somebody edits your file with the proper editor, it may remove the
extra characters and your program will no longer work.

You should determine exactly what the extra characters are and remove
them. chop will remove the last character of your string, regardless of
what it is.

In your original program, which you do not show, you have already used
chomp on the lines read from your file, and the chomp shown above is a
no-op. chomp will remove the expected line-ending character or
characters from a string. If they are not found, chomp does nothing.

Use the substitute operator or the tr operator to remove only those
characters that do not belong:

s/[\r\n]+//;
tr/\r\n/d;

--
Jim Gibson

Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com

Posted by monk on March 3, 2008, 8:25 pm
Please log in for more thread options
> In article
>
>
>
> > Thanks for the tip 'od -c <filename>'
>
> > I uncovered an extra character was being added somehow when slurping
> > the config file.
> > I added one little line to my code and now it works like a charm.
>
> > foreach (@directories_to_clean){
> > chomp;
>
> > chop; # one extra line that solved my problem.
>
> > print "$_\n";
>
> > #and everything else is the same
>
> > }
>
> That is not a good, long-term solution. It is not likely that slurping
> the file is adding extra characters. It is more likely that the file
> does not have the proper line endings for your system. As soon as
> somebody edits your file with the proper editor, it may remove the
> extra characters and your program will no longer work.
>
> You should determine exactly what the extra characters are and remove
> them. chop will remove the last character of your string, regardless of
> what it is.
>
> In your original program, which you do not show, you have already used
> chomp on the lines read from your file, and the chomp shown above is a
> no-op. chomp will remove the expected line-ending character or
> characters from a string. If they are not found, chomp does nothing.
>
> Use the substitute operator or the tr operator to remove only those
> characters that do not belong:
>
> s/[\r\n]+//;
> tr/\r\n/d;
>
> --
> Jim Gibson

Jim, you're absolutely right.
So yeah, using <od -c filename> I identified the extra characters that
were added and then used regular substitution. This is a much more
efficient approach. Now I'm just removing only the ones I need. Not
just whatever was there.

thanks,




Posted by Tad J McClellan on February 27, 2008, 8:31 pm
Please log in for more thread options

><http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html>
> (currently not accessible to me) and posted here twice a week.


It changed location last summer (at revision 1.8):

http://www.rehabitation.com/clpmisc.shtml
or
http://www.rehabitation.com/clpmisc/clpmisc_guidelines.html


--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher0cmdat/"

Similar ThreadsPosted
Parent process unable to read messages from child process February 28, 2007, 12:38 pm
Parent process unable to read messages from child process February 28, 2007, 12:38 pm
what is %process XX% October 28, 2004, 1:12 pm
PLEASE help me with this process June 17, 2005, 1:18 pm
get process name from process id July 17, 2008, 1:18 pm
killing a process using its PID September 13, 2004, 4:51 pm
process control September 28, 2004, 12:12 am
Need help with the "System" process April 11, 2006, 8:14 am
kill the process July 7, 2006, 3:51 pm
Perl API to be used as process. November 29, 2006, 7:39 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap