Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Cultural and Bibliometric Perl

by jeroenes (Priest)
on Jun 29, 2001 at 15:26 UTC ( #92583=note: print w/ replies, xml ) Need Help??


in reply to Cultural and Bibliometric Perl

Some comments:

  1. use strict warnings and diagnostics or die
  2. The file regex may produce some unwanted results with unix-like filenames: file.txt.bak . Just think which part you want to retain. You can find the first and last dot with index and rindex, respectively.
  3. You slurp the contents in array context only to join the array. You can also set $/ to undef:
    { local $/ = undef; $contenido = <LIBRO>; }
    You can leave the newlines intact, they will be catched with '\s'. Even better, tr will take care of that.
  4. Use lc or uc to change the case.
  5. You can simplify the translation, by complementing the list to the alphabetic range (see perlop):
    $contenido = uc $contenido; $contenido =~ tr/A-Z/ /cs;
  6. Use '\s+' rather than '\s', so you don't have to test for empty cases.
  7. You can get the total number without array assignment: $npalabras = keys %PF; The scalar context will force immediate size return.
  8. I would print LIBROUT in the while loop, so the system will get the chance to buffer nicely.
It's quite a list, but I hope it will give you the chance to learn new idiom. Result:
#.... my $contenido; { local $/ = undef; $contenido = <LIBRO>; } $contenido = uc $contenido; $contenido =~ tr/A-Z/ /cs; my %PF; $PF{$_}++ for( split /\s+/, $contenido); open LIBROUT, ">$ar.csv"; my $npalabras = keys %PF; while( keys %PF ){ print LIBROUT join ';', $_, my $f=$PF{$_}, $f/ $npalabras; print LIBROUT "\n"; }
Well, you see how the use of $_ simplifies things..

Hope this helps,

Jeroen
"We are not alone"(FZ)


Comment on Re: Cultural and Bibliometric Perl
Select or Download Code
Re: Re: Cultural and Bibliometric Perl
by Ignatius Monk (Novice) on Jun 29, 2001 at 15:53 UTC
    Dear friend:
    Thanks a lot by your suggestions :). I made this code at the beggining of my perl efforts and I hadnīt open It until I pasted It on the post, and of course the code was very simple :) I can see that your is much better.
    I'm just going to buy on the net the 3rd edition of the programming perl (because it hasn't arrived to the Spanish market by now) to have a better knowledge of the programming language :) the problem is that I'm totally self-teached on computer sciences (I program on VB C and now Perl but learning on my own way, buying books, downloading tutorials, etc) and I advance too slow sometimes, I suppose that with that reference book I'll learn better 'programming skills' from now on ;)
    Best regards
    Ignatius, the Ciberlibrarian Monk on the Perl Order ;)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://92583]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2014-12-21 18:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (106 votes), past polls