Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: remove 16 Zeros

by ww (Archbishop)
on Oct 13, 2015 at 12:20 UTC ( [id://1144688]=note: print w/replies, xml ) Need Help??


in reply to remove 16 Zeros

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 }"

  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....).
  2. 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.
  3. Then -- as written -- your curly braces enclosing the zeros are a quantifier for how many times to match "s"
  4. 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.

Replies are listed 'Best First'.
Re^2: remove 16 Zeros
by eghdam (Initiate) on Oct 13, 2015 at 12:46 UTC
    thank u very much. I am just in Process to get to manual. again thank u.

      Your installation of Perl includes a "manual". Use the perldoc command to access it.

      Also, all of the "official" Perl documentation is available online at http://perldoc.perl.org

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1144688]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2024-03-29 06:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found