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?