--- "WANG, SHIPING [AG/1000]" <[EMAIL PROTECTED]> wrote:
> Hi, Question for your code:
>
> what is the meaning "require 5;"
Require with just a version number means that you must be running Perl 5 or better.
For example,
let's say I was to use the 'our' keyword. That was introduced in 5.6,
Hi, Question for your code:
what is the meaning "require 5;"
-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Friday, December 28, 2001 3:54 PM
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Subject: RE: Question!! number of line
requi
"Leon" <[EMAIL PROTECTED]> writes:
[...]
> (1)how to make a variable within loops non-lexical as in this eg:-
> while (){
> my $count++; # how to globalised this variable?
$count++; # NO "my", therefore implicitly global.
> };
>
> (2)how to make a variable availab
- Original Message -
From: "John W. Krahn" <[EMAIL PROTECTED]>
> Leon wrote:
> >
> > - Original Message -
> > From: "Mark Mclogan" <[EMAIL PROTECTED]>
> > > How I can know in that I number of line finds a word in a text file?.
> > > For example, a file "file.txt" contains the foll
Hiya Mark,
Something like this should work:
#!/usr/local/bin/perl -w
use strict;
my $file = "file.txt";
open (READ, "<$file") || die "Can\'t open file: $!";
my @list_of_words = ;
close (READ) || die "Can\'t close file: $!";
my $counter = 1;
foreach my $word (@list_of_words){
++$counter;
Oops.. I made some mistake, sorry =)
should be like this :
###
open (FILE, ")
{
@lineNumber = (@lineNumber, $count) if ($_ eq "apple\n") ;
$count++;
}
close (FILE);
###
PS. if you have only 1 apple, then it valued at $lineNumber[0];
h
open (FILE, ") { if ($_ eq "apple\n") { $count++ } }
close (FILE);
you got the result at $count
have a nice day =)
- Original Message -
From: "Mark Mclogan" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, December 29, 2001 5:36 AM
Subject: Question!! number of line
Leon wrote:
>
> - Original Message -
> From: "Mark Mclogan" <[EMAIL PROTECTED]>
> > How I can know in that I number of line finds a word in a text file?.
> > For example, a file "file.txt" contains the following list:
> >
> > Chocolate
> > Cake
> > Cheese
> > Apple
> > orange
> > melon
>
- Original Message -
From: "Mark Mclogan" <[EMAIL PROTECTED]>
> How I can know in that I number of line finds a word in a text file?.
> For example, a file "file.txt" contains the following list:
>
> Chocolate
> Cake
> Cheese
> Apple
> orange
> melon
> lemon
>
> How I can know in that l
require 5;
sub get_line_num
{
my ($file_name, $string_to_look_for) = @_;
my $line_num = -1;
open ( MYFILE, $file_name ) or die "Error opening file '$file_name'.
Reason is <$!>";
while ( )
{
if ( /$string_to_look_for/i ) { $line_num = $.; last; }
}
close( MY
> -Original Message-
> From: Mark Mclogan [mailto:[EMAIL PROTECTED]]
> Sent: Friday, December 28, 2001 4:37 PM
> To: [EMAIL PROTECTED]
> Subject: Question!! number of line
>
>
>
> How I can know in that I number of line finds a word in a text file?.
> For example, a file "file.txt"
11 matches
Mail list logo