In general, you might like to have a look at the format, also the assignment in
while ($_=<DATA>)... is superfluous -
while (<DATA>)... does exactly the same thing.
As to the exact problem, using strictures would have given you a clue to solving the problem since, assuming you rewrite $x =~ /^\[Note\](\w+)/; to my $x =~ /^\[Note\](\w+)/; (to remove the undeclared variable error that would otherwise ensue), you would have seen a use of uninitialised value in pattern match... error, the solution to which is (my $x = $_) =~ /^\[Note\](\w+)/;.
Having done all that, you can then go on to solve the problem of extracting the value from the field - maybe along the lines of $x =~ s/[^,]*,//;, so the final code should, IMO, look like:
<p>#!/usr/bin/perl
use warnings;
use strict;
while (<DATA>){
(my $x = $_) =~ /^\[Note\](\w+)/;
$x =~ s/[^,]*,//;
print $x;
}
__DATA__
[Note]note_values,notes_values2
[Book]novels,magazines
Which generates:
$ perl tst.pl
notes_values2
magazines
$
As required. It then becomes a trivial exercise to ignore lines of no interest...
A user level that continues to overstate my experience :-))
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.