You have several problems.
- You are converting your 'NULL' strings to undefs before you do the substitutions to remove the quotes.
If you had warnings enabled you would see that this causes two "Use of uninitialized value in substitution (s///) at ..." messages. One for each of the undefs.
A simple solution to this is to reverse the order of your maps.
- Your substitution map is returning the result of the substitution hence the two 1s. One for each of the two values that are matched '196' and 'berg'.
The simple answer here is to make sure that the result of the map (the last value in the code block) is $_.
- According to your text, you only want to strip 's around the number, but your substitution is also stripping them from 'berg'.
This may just be words, but if you really only want to strip them from the number(s) then you should change thematch in the substitution to s/^\'(\d+?)\'$/....
Your also backwacking more than is necessary. Putting that all together we get
my $params = "'196', 'berg',NULL,NULL";
my @list_of_params = map {
$_ eq 'NULL' ? undef : $_
} map {
s/^'(\d+?)'$/$1/m; $_
} split /\s*,\s*/, $params ;
It's probably not the way I would have done it, but it does correct some errors and produce the output you want.
Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller
If I understand your problem, I can solve it! Of course, the same can be said for you.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.