Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^4: Count similar characters in a row - only once

by $new_guy (Acolyte)
on Jun 29, 2011 at 10:47 UTC ( #911928=note: print w/replies, xml ) Need Help??


in reply to Re^3: Count similar characters in a row - only once
in thread Count similar characters in a row - only once

I have edited the script above as follows (below): it writes out a temporary file that I will use while running my second script. The second script will now take the temporary file which I will delete afterwards. Please critisize as it must be 100% accurate.

#!/usr/bin/perl use strict; use warnings; my $file = 'my_data_file.txt'; my %seen = (); { local @ARGV = ($file); #remove all previous re-organized files my $remove = "my.txt.tmp"; if (unlink($remove) == 1) { print "Existing \"$remove\" file was removed\n +"; } while(<>){ #now make a file for the ouput my $outputfile = "my.txt.tmp"; if (! open(POS, ">>$outputfile") ) { print "Cannot open file \"$outputfile\" to write to!!\n\n" +; exit; } $seen{$_}++; if($seen{$_} !~/-/g){ next if $seen{$_} > 1; print POS; } } } print "\n\nfinished processing file.\n";

Replies are listed 'Best First'.
Re^5: Count similar characters in a row - only once
by Anonymous Monk on Jun 29, 2011 at 13:11 UTC

    Please critisize as it must be 100% accurate.

    Does it perform the transformation you wanted correctly?

    If so, here is my criticism

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://911928]
help
Chatterbox?
[shmem]: Discipulus: while (readdir DIR) works fine
[Discipulus]: Eataly vs World(coffe) ;=)
[Discipulus]: shemem i wrote it directly.. but when i tested it i got a lot of 'undefined value..'
[Corion]: Oh, poor Trump can't get a break. Even the Vatican only sends the second in command to greet him...
[shmem]: Discipulus: readdir has the same semantics as readline (a.k.a <>). Have another coffee ☕ ;-)
[Discipulus]: ah! just with my old system perl (5.8.8) was needed
[Corion]: Has anybody toyed around with Mastodon? There is a Perl module for it, but I'm not sure that it's a yak worth chasing
[Corion]: On the upside, maybe running that for my family would be interesting, or at least for myself
[Corion]: I'm not fond of using a server hosted by other people, even if they claim to be GNU ;)

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (8)
As of 2017-05-26 07:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?