Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

I/O difference between 5.6.0 and 5.8.0

by billp (Initiate)
on Jul 14, 2004 at 15:31 UTC ( #374317=perlquestion: print w/replies, xml ) Need Help??
billp has asked for the wisdom of the Perl Monks concerning the following question:

sincerly sorry, windows (pick a flavor: XP Pro, 2000, 2003 server), using cygwin. a bit long perhaps but this example should display the problem.
#!/usr/bin/perl -w use strict; #use Getopt::Long; use IO::File; # Reads a file and returns it as a string # `fileName' the name of the file to be read # returns the content of the file as a list of lines in list context # or as a string in scalar context sub getFile($) { my ($fileName) = @_; print("getFile: $fileName\n"); local *IN; open(IN, "<$fileName") or die("Error open($fileName): $!"); if (wantarray) { my @line = <IN>; return map { my $value = $_; chomp($value); $value; } @line; } else { my $fileValue = join("",<IN>); chomp($fileValue); return $fileValue; } } sub getLocalConfig($) { my ($file) = @_; my @localCfg = getFile("$file"); # reorganize the list so that all space delimited items are # individual elements my $flat = join(" ", @localCfg); # remove any extraneous whitespace $flat =~ s/\t\r\f\n//g; @localCfg = split(/ /, $flat); return @localCfg; } sub readLocalConfig($) { my ($cfgName) = @_; print("Reading local configuration\n"); # read a local config file .build-cfg if (-e "$cfgName") { return getLocalConfig("$cfgName"); } else { print("No local config file\n"); } } sub main() { @ARGV = readLocalConfig("build-cfg"); print(@ARGV); print("\n"); # hand this off to GetOptions::Long to parse } main();
using the following build-cfg file:
--hello --setThis=2 --helloAgain --setString=bye
on 5.8.2 this prints only the last entry --setString=bye whereas using 5.6.0 all entries are recovered. the point of the file being to preset command line options to the script. Again, sorry for the lack of initial information and thanks for the reponses. bill

Replies are listed 'Best First'.
Re: I/O difference between 5.6.0 and 5.8.0
by crabbdean (Pilgrim) on Jul 14, 2004 at 15:52 UTC
    A copy of the code, your config file and exactly what error you are getting would prove helpful. Otherwise any answers are a stab in the dark. With the code it might just a be case of a syntax problem ... but we won't know until we see it.

    The Funkster of Mirth
    Programming these days takes more than a lone avenger with a compiler. - sam
    RFC1149: A Standard for the Transmission of IP Datagrams on Avian Carriers
Re: I/O difference between 5.6.0 and 5.8.0
by graff (Chancellor) on Jul 15, 2004 at 01:47 UTC
    There are profound differences between 5.6.0 and 5.8.0 that involve reading text from files (and these differences can cause unexpected problems on at least on some versions of Linux, possibly other OS's as well). Also, some "features" of 5.8.0 have since been "modified" -- the current stable release is 5.8.4 -- so that there are fewer bothersome differences in behavior relative to 5.6.0 (and earlier versions). For that matter, some of those Linux versions may have been updated to avoid some problems as well (I don't know).

    That's all very vague, but as crabbdean has pointed out, so is your question. You must at least be able to make time to tell us in detail what you mean when you say "the script fails to read a config file correctly." Does it give an error message (and if so, what's the message)? Does it report no errors but end up with unexpected data?

    While you're at it, it would be relevant (if you can spare a few more seconds) to say what OS type/version you're on, and indicate whether there is any non-ASCII data in the config file.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://374317]
Approved by gellyfish
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (10)
As of 2017-11-22 15:48 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (326 votes). Check out past polls.