On Fri, Aug 15, 2003 at 11:44:04PM -0600 Robert Mark White wrote:

> Please be gentle with me as this is only my first day trying to learn perl.
> I am using an online tutorial, however it must be written for *nix and I am
> trying to use it on win32.
> man perl does not even work.

We'll come to that later...

> I have already found some other differences.  For example, the tutorial uses
> single quotes and to get anything
> to work I had to use double quotes. There must be other things that are
> different also.
> I tried to use the examples directly in an script that would be useful to
> me. Maybe I should have tried
> something a little simplier.
> 
> Any polite suggestions would be greatly appreciated.
> 
> Sincerely yours,
> 
> 
> Robert Mark White
> 
> 
> The attempted script is below
> Most of the lines below are directly from the tutorial so.....what!
> I think at least  the "#" remark lines below should be correct!
> 
> ----------------------------------------------------------------------------
> ------------
> # By RMW
> # using activeperl v5.8.0 for Win32-x86-multi-tread
> # Program to add file1 to file2
> # examples from http://www.comp.leeds.ac.uk/Perl/filehandling.html
> 
> #name the files
> $file1 = "c:\Program Files\ArGo Software Design\Mail Server\Keyring_ALL";  #
> Name for file1
> $file2 = "c:\PGP\pgp-all.asc";          # Name for file2

You are trying to be too smart here. Even on Windows it is totally ok to
use forward-slashes in pathnames. Perl will do the right thing for you:

    $file1 = "c:/Program Files/ArGo Software Design/Mail Server/Keyring_ALL";
    $file2 = "c:/PGP/pgp-all.asc";

What you did couldn't work because you used double-quotes in which '\'
is the escape character. For unknown sequences such as '\p' the result
is simply 'p'. So if you want a literal backslash appear in your
double-quoted strings, you need to escape it: "\\". 

Now, talking about RTFM. You don't have man available, so far right. But
if you have a Perl distribution, you most likely have the perldoc
program. So try

    perldoc perl

in a DOS-prompt. It lists all the other manual pages that are available.
To learn about how to build strings, read

    perldoc perldata

and search for "String literals" or similar.

Depending on your Perl distribution, the documentation is probably also
available as HTML. In case of ActivePerl, you'll find an entry in the
startmenu's group of ActivePerl pointing to the documentation ("Help" or
so).

> open(INFO, ">$file2");   # Open file2 for output
> @lines = <INFO>;          # Read file2 into an array

INFO is a write-only filehandle so you can't read from it. 

> close(INFO, "$file2");   # Close the file2
> 
> open(INFO, "<$file1");   # Open file1 for input
> print <INFO> = @lines;          # Print the array into file1

Even if the above syntax was valid, it wouldn't work because here the
file has been opened for reading. Also, <HANDLE> is used to read from a
filehandle and not to write to it.

> close(INFO, "$file1");   # Close the file1

The above would have to look like:

    open INFO_IN, "<$file2" or die "Error opening for read-access: $!";
    @lines = <INFO_IN>;
    close INFO_IN;

    open INFO_OUT, ">$file1" or die "Error opening for write-access: $!";
    print INFO_OUT @lines;
    close INFO_OUT;

There are better ways of doing the above. For instance, you don't need
@lines at all. Do it all in one go:

    open INFO_IN, "<$file2" or die "Error opening for read-access: $!";
    open INFO_OUT, ">$file1" or die "Error opening for write-access: $!";

    print INFO_OUT <INFO_IN>;

    close INFO_IN;
    close INFO_OUT;

For very large files this may need too much memory (perl internally has
to read the file into a large list), so do it line-wise:

    print INFO_OUT $_ while <INFO_IN>;

This is a good moment to read 'perldoc perlsyn' and learn about this
syntax (it uses someting called 'statement modifiers').

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to