Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

VarStructor II -- Abbreviation tool

by Wassercrats (Initiate)
on Apr 20, 2004 at 13:40 UTC ( [id://346625]=sourcecode: print w/replies, xml ) Need Help??
Category: Utility Scripts
Author/Contact Info barry@polisource.com
Description:

Similar to Text::Abbrev (Text::Abbrev output example here). I intend to use it to create unique variable names based on the first few characters of the variables' values (the elements of @Lines). Variables that are still identical get numbered.

It's already set up as a demo, so try it out and see how it differs from Text::Abbrev and similar modules.

@Lines contains demo phrases to be abbreviated. The configuration options are $Max_Length (of returned phrases), $Letters_Only (1=yes, 0=no), and $Replacement (string that replaces non-letters).

The code is full of global variables, not enough comments, and probably other bad stuff, but I know that's what everyone loves about me. I intend to fix it up. Maybe.

Code removed by author. I no longer want to contribute to this community.
Replies are listed 'Best First'.
Re: VarStructor II -- Abbreviation tool
by jeffa (Bishop) on Jun 01, 2004 at 14:18 UTC

    Since you give no usage what so ever, i can only speculate just exactly what you want to output to look like. And more importantly, what the "rules" are. But i can say that you have a lot of needless code there. Try this instead:

    use Data::Dumper; my (%symbol,@old,@new); my $max = 10; my $ws_replace = '_'; my $letters_only = 1; while (<DATA>) { chomp; push @old, $_; $_ = substr $_,0,10 if $max; s/\s+/$ws_replace/g if $ws_replace; s/\W+//g if $letters_only; $_ .= $. if $symbol{$_}++; push @new, $_; } print Dumper \@old, \@new; my %compare; @compare{@old} = @new; print Dumper \@compare; __DATA__ Line one Line two xxxxxxxxxxx Another line xxxxxxxxxxx Lines end here not xxxxxxxxxxx Fourth line (used to be) Line five Lines end here Lines end here too
    And read The Dynamic Duo --or-- Holy Getopt::Long, Pod::UsageMan!

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: VarStructor II -- Abbreviation tool
by herveus (Prior) on Apr 22, 2004 at 13:37 UTC
    Howdy!

    I'm puzzled.

    Why would I want to do this? I've looked at this several times over the past couple days trying to figure out the point. Can you explain what you mean to actually use this for? My "code smell" sniffer keeps wanting to tell me you are working up to symbolic references and the like.

    yours,
    Michael
    A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2024-11-10 09:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    chatterbot is...






    Results (37 votes). Check out past polls.