×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Problem with Unix to NT Perl script

Problem with Unix to NT Perl script

Problem with Unix to NT Perl script

(OP)
How do I convert a Perl Script written under Unix to work under Perl for Win32 on NT?

RE: Problem with Unix to NT Perl script

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).
 

You might want to post your code.

Thanks.

-Vic

RE: Problem with Unix to NT Perl script

(OP)
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 "beginning of sentence"
$bos=0;
# Track if we have read a "continuation of sentence"
$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 "") {

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

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

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

  $count++;
}

RE: Problem with Unix to NT Perl script

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

RE: Problem with Unix to NT Perl script

Hi,

I see a lot of people using syntax like this and I'm a bit puzzled:

# 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 "") {

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?


while(<>){
# process each line of file
    print; # print processed line
}


What am I missing here? Is there some obvious advantage to @input=<STDIN>;while($input[$count++]) that I'm just not seeing?

Mike
michael.j.lacey@ntlworld.com
Cargill's Corporate Web Site

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close