in reply to regex code embedding problem?

I'm not quite sure why you feel you need to execute the code inside the regex. perldoc perlre says that code is highly experimental.

I'd do it like this:

if ($file_name =~ m# (?<=/a/) (\d{2,4})(\d{2})(\d{2})(?:ag)?#x) { @date{'YEAR', 'MONTH', 'DAY'} = (( length($1) == 2 ? '19' . $1 : $1), $2, $3 ),$2,$3); }
Am I overlooking some reason why that wouldn't work for you?

Replies are listed 'Best First'.
Re: Re: regex code embedding problem?
by perlguy (Deacon) on Mar 12, 2004 at 23:40 UTC

    Well, for one, I wasn't seeking a true/false value from the regular expression; I'm simply using the engine to do some dirty work. The question I have really hasn't been answered even if the code you posted works. I'd like to know why the hash is cleared upon exiting the regex, when it is quite obviously (or so I think) populated upon successful matching of the lookbehind, matching pattern, and then lookahead.

    I know that embedded code in a regex is experimental. The code I'm writing is write once, execute once, and then never look at again. I generally don't write code like this, especially not in production, but when I came across what I felt was something strange, I simplified the code down to what I felt to be the simplest case that generated the problem, and then asked about it.