Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with Unix to NT Perl script 1

Status
Not open for further replies.

iczer

Technical User
Aug 15, 2000
2
US
How do I convert a Perl Script written under Unix to work under Perl for Win32 on NT?
 
It would depend on the type of script you have. If you have a script that has heavy use of the systems commmands, it would take considerable longer than if you just had something open a text file and print to it (say for example).<br>&nbsp;<br><br>You might want to post your code.<br><br>Thanks.<br><br>-Vic
 
Vikter,

Thanks

Here is the code I was tring to get to work under Perl for Win32.
This script is to parse a large text file into a format that I need.

#!/usr/local/bin/perl

$count=0;
# Track if we have read a &quot;beginning of sentence&quot;
$bos=0;
# Track if we have read a &quot;continuation of sentence&quot;
$cos=0;

# read in the file
@input = <STDIN>;
# trim off the newline from the end of each line
chop (@input);

# Process the file
while ($input[$count] ne &quot;&quot;) {

# strip leading white space
$input[$count] =~ s/^[ \t]+//;

# Look for &quot;beginning of sentence&quot;
if (substr($input[$count],0,2) eq &quot;o &quot;) {
if ($bos || $cos) {
print(&quot;\n&quot;);
$cos=0;
}
$input[$count] =~ s/^o //;
print ($input[$count]);
$bos=1;
}

else {
print (&quot; &quot;,$input[$count]);
$bos=0;
$cos=1;
}

$count++;
}
 
Iczer:

I don't see anything wrong with that. Have you tried to convert it and seen what happens? Do you get an error message. Otherwise, I don't see a problem with it.


I tried it on my machine, which is Win32 and running ActiveState Perl. It found nothing wrong with it.

Hope this helps.

-Vic
 
Hi,

I see a lot of people using syntax like this and I'm a bit puzzled:
[tt]
# read in the file
@input = <STDIN>;
# trim off the newline from the end of each line
chop (@input);

# Process the file
while ($input[$count] ne &quot;&quot;) {
[/tt]

to read through the contents of a file and process each line, and there's nothing wrong with it (works fine) however...

It seems to me that if you have a large file - you will use a lot of memory that way; wouldn't it be better (so that you can deal with files of any size) to do it like this?

[tt]
while(<>){
# process each line of file
[tab]print; # print processed line
}
[/tt]


What am I missing here? Is there some obvious advantage to [tt]@input=<STDIN>;while($input[$count++])[/tt] that I'm just not seeing?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top