Frankly, I find your question hard to understand... and not just because you failed to use proper markup -- i.e., code tags (<c> ... </c>) around data and code. Please see the markup instructions at the text entry box or read Writeup Formatting Tips).
But addressing what I surmise you may think is a partial approach to your problem (including the possibility of a variable char count before your 16 zeros), the following should do the job:
#! /usr/bin/perl -w
use strict;
# 1144651
my $pvid;
my $line = "pvid 00c1be9a467335ce0000000000000000";
if ($line =~ /(pvid .*?)0000000000000000$/ ) {
$pvid = $1;
}
print $pvid;
Your "partial approach"
" if ($line =~ /pvid\+(.*$)s{0000000000000000}{ $pvid = $1 }"
- provides no mechanism to capture the initial four chars, "pvid", nor any limitation on how many times to accept what the dot represents (a single instance of anything, char, num, symbol....).
- In a regex, the "$" marks the end of an input line, so an input with additional data -- if you had any limit on the .* (anything, any number of times) -- would never match.
- Then -- as written -- your curly braces enclosing the zeros are a quantifier for how many times to match "s"
- Finally, you don't terminate the "partial approach's" regex with a closing slash, "/".
As a prophet once said, you can't just make stuff up and expect the computer to understand.
Note also the "my $pvid which makes the variable global, and allows perl to pass its content back to the code outside the if clause.
As others observed, best you read docs such as perldoc perlre and perldoc perlretut... available at your own console... and perhaps tutorials (Tutorials) here such as Getting Started with Perl.
Updated: textual typos corrected and formatting changed for readability.
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.