Newbies probleme

O

Orion93

Actually i try to make a script to compte all lines of all pl files. Also i
find how to do it for one file but no for all of them. Try to use opendir
but i don't understand how to use it!

Please help me!

See my script:

#!/usr/bin/perl
sub recupPages
{
my $nomFic = shift;
my $result = shift;

# Récupération des lignes du fichier
open(F,$nomFic);
open(SORTIE,">> $result");
$i = 0;
while(<F>)
{

$i ++;
}
print SORTIE " $nomFic $i\n";

close F;
close SORTIE;}

my $emplacement = "C:\\stat\\test.pl";
my $ficResultat = "C:\\result.txt";
recupPages($emplacement,$ficResultat);

Tks for all!
 
W

Web Surfer

[This followup was posted to comp.lang.perl.misc]

Actually i try to make a script to compte all lines of all pl files. Also i
find how to do it for one file but no for all of them. Try to use opendir
but i don't understand how to use it!

Please help me!

See my script:

#!/usr/bin/perl
sub recupPages
{
my $nomFic = shift;
my $result = shift;

# Récupération des lignes du fichier
open(F,$nomFic);
open(SORTIE,">> $result");
$i = 0;
while(<F>)
{

$i ++;
}
print SORTIE " $nomFic $i\n";

close F;
close SORTIE;}

my $emplacement = "C:\\stat\\test.pl";
my $ficResultat = "C:\\result.txt";
recupPages($emplacement,$ficResultat);

Tks for all!


opendir(DIR,"$dirname") ||
die("opendir failed for $dirname : $!\n");
@entries = readdir DIR;
closedir DIR;

print "The files under $dirname are : ",
join(", ",@entries),"\n";
 
G

Gunnar Hjalmarsson

Orion93 said:
Actually i try to make a script to compte all lines of all pl
files. Also i find how to do it for one file but no for all of
them. Try to use opendir but i don't understand how to use it!

It's easier to just change the last line to:

recupPages($_, $ficResultat) for glob 'C:/stat/*.pl';

See http://www.perldoc.com/perl5.8.0/pod/func/glob.html
See my script:

#!/usr/bin/perl

use strict;
use warnings;
sub recupPages
{
my $nomFic = shift;
my $result = shift;

# Récupération des lignes du fichier
open(F,$nomFic);
open(SORTIE,">> $result");
$i = 0;

open F, $nomFic or die "Couldn't open $nomFic\n$!";
open SORTIE, ">> $result" or die "Couldn't open $result\n$!";
my $i = 0;

Hope that helps.
 
T

Tore Aursand

Actually i try to make a script to compte all lines of all pl files.

What does 'comte' mean? Compute?
Try to use opendir but i don't understand how to use it!

Documentation:

perldoc -f opendir

Example:

opendir( DIR, '/' ) or die "$!\n";
my @all_files = readdir( DIR );
closedir( DIR );


--
Tore Aursand <[email protected]>
"Scientists are complaining that the new "Dinosaur" movie shows
dinosaurs with lemurs, who didn't evolve for another million years.
They're afraid the movie will give kids a mistaken impression. What
about the fact that the dinosaurs are singing and dancing?" -- Jay
Leno
 
P

Polleke

What does 'comte' mean? Compute?

compte (not comte) comes - if memory serves - from the Frech verb
'compter' which means 'to count'. So OP wants to count the numer of lines
each .pl-file containes.

Paul
 
O

Orion93

compte (not comte) comes - if memory serves - from the Frech verb
'compter' which means 'to count'. So OP wants to count the numer of lines
each .pl-file containes.

Paul

Exact i'm french! sorry for my bad English!
 
T

Tore Aursand

compte (not comte) comes - if memory serves - from the Frech verb
'compter' which means 'to count'. So OP wants to count the numer of lines
each .pl-file containes.

Ah. Sorry about my bad French. :) Something like this (untested) should
do the trick:

#!/usr/bin/perl
#
use strict;
use warnings;

## Where to search?
my $dir = '/perl/scripts';

## Create a list of files ending with '.pl'
opendir( DIR, $dir ) or die "$!\n";
my @files = grep { /\.pl$/ } readdir( DIR );
closedir( DIR );

## Process each file
foreach ( @files ) {
open( PL, "$dir/$_" ) or die "$!\n";
my @lines = <PL>;
close( PL );

print $_ . ' has ' . @lines . "\n";
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top