Hey Folks I was hoping someone could explain this to me. Normally I
used perl in unix and I do the following command.
$filename = "data.dat";
@temp =split("\.","$filename");
Well, that's your problem right there, most likely. If you read the
documentation for the 'split' function with 'perldoc -f split', you
will see that the first parameter is a regex, not a string. I'm just
about to leave, so I'm not going to figure out why this works, but
it's quite possible it's pure luck that it works for you.
I expect someone will prove that last sentence to be pure balderdash,
so I'm not standing behind it very strongly.
For some reason this does not work with Perl on Windows. However if I
do the following change from " to / it works.
$filename = "data.dat";
@temp =split(/\./,"$filename");
Why is that? Can anyone provide me with an explanation.
Perl itself can provide you with an explanation, if you read the
standard documentation included with your Perl distribution. I say
this not to be a sanctimonious git, but to help you not offend too
many other people here, who are very knowledgable about Perl and could
be a lot of help to you if you let them: please try not to ask
questions here that you could answer in about 20 seconds on your own.
If you have a question about how a function works, use the command
perldoc -f <function>
on the command line.
For a module's documentation, use
perldoc <module>
You should also familiarize yourself with the Perl FAQ. 'perldoc
perltoc' will give you the headings of the sections and what questions
are answered in them. If you always check there first, to make sure
your question isn't answered in the FAQ (or any of the other resources
I mentioned), you stand a much better chance of getting answers more
verbose than "read the documentation".
Should I not use " and stick with /'s or the q's? I'm going to be
writing a lot of cross-platform (unix, windows) code.
You should also familiarize yourself with the perlport manpage ('man
perlport' on UNIX, or 'perldoc perlport' everywhere). But no matter
what kind of code you write, learning to consult the documentation on
your hard drive first will save you lots of time (USENET propogation
is not consistent or necessarily even complete), and will save us lots
of frustration. A win for everyone, I think.
-=Eric