Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: regex question

by hippo (Chancellor)
on Apr 01, 2020 at 17:53 UTC ( #11114917=note: print w/replies, xml ) Need Help??


in reply to regex question

As Corion has answered your question, here's just a simpler (IMHO) approach to the task:

#!/usr/bin/env perl use strict; use warnings; use Data::Dumper; my $s = "1 A\n2 B\n"; my %h = split /\s/, $s; print Dumper(\%h);

Replies are listed 'Best First'.
Re^2: regex question
by morgon (Priest) on Apr 01, 2020 at 19:34 UTC
    Very imaginative, but in reality my lines look not like "1 A" but rather like "1 string1 string2 string3" and so your approach would not work anymore.

    But your idea is cool.

      Clear questions elicit clear and helpful answers. What should the content of your hash look like given the new data format? Do any of the other solutions given so far produce that structure | hash content?


      Give a man a fish:  <%-{-{-{-<

      If you want to match "1 string1" from "...\n1 string1 string2 string3\n...", use anchor '^', otherwise modifier 'm' is redundant. Did it help?

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2020-06-06 09:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you really want to know if there is extraterrestrial life?



    Results (41 votes). Check out past polls.

    Notices?