Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^3: iterating hash keys?

by kcott (Chancellor)
on Sep 28, 2013 at 06:29 UTC ( #1056105=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    $ cat pm_1055846_name_id_data.txt
    bananas 456
    ...
    bana 20
    bana-na 15
    na 10
    
  2. or download this
    $ cat pm_1055846_name_replace_data.txt
    bananas,oranges
    ...
    bananas,oranges,pineapples,peaches,kiwis
    bana-na,banana
    ba-na-na,bana-bana,bana-nana
    
  3. or download this
    $ cat pm_1055846_name_replaced_out.txt
    456,23
    ...
    456,23,pineapples,897236,3726
    15,25
    ba-10-10,20-20,20-nana
    
  4. or download this
    my $re = '\b(' . join('|', keys %id_for) . ')\b';
    
  5. or download this
    my $re = '\b(' . join('|', sort { $b cmp $a } keys %id_for) . ')\b';
    
  6. or download this
    $ cat pm_1055846_name_replaced_out.txt
    456,23
    ...
    456,23,pineapples,897236,3726
    15,25
    ba-na-na,bana-bana,bana-nana
    
  7. or download this
    my $re = '\b(' . join('|', keys %id_for) . ')\b';
    
  8. or download this
    my $re = '(^|,)(' . join('|', sort { $b cmp $a } keys %id_for) . ')(?=
    +,|$)';
    
  9. or download this
    s/$re/$id_for{$1}/g;
    
  10. or download this
    s/$re/$1$id_for{$2}/g;
    

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1056105]
help
Chatterbox?
[hippo]: Indeed you are.
[thao4]: Hi all, I am new in perl. I need do somthing in perl: exemple: - search a patern "CADRE 1.1 CPU" in one file.txt - incremente +30 lines from the line with the patern found - replace the patern "Model Regle" by "Heath Rule A" in this new line (30 line
[marto]: good morning all
[hippo]: Welcome. Tell me, have you read perlintro? That's a great place to start.
[thao4]: I seach to do that since a week but I can't found the answer in google. Thank for your help
[Eily]: hello thao4 (and hello all :D), you should [id://http:// perlmonks.org/ index.pl?node_id= 479#post|open a question on Seekers of Perl Wisdom], be sure to include whatever you have tried that didn't work, or only does the job partially
[thao4]: yes, I do a little perl since some years but not fréquently, I can correct the triggers in Clearcase of IBM, but write the code : no
[Eily]: meh, such good link ...
[Eily]: here
[Eily]: still not xD there

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (10)
As of 2018-02-21 09:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When it is dark outside I am happiest to see ...














    Results (276 votes). Check out past polls.

    Notices?