I'm having trouble counting the number of characters in a DATA block in my script. Each line contains 6 fields separated by the pipe symbol '|'. In trying to sanitize the data before entering it into a DB I want to ensure each line contains 5 pipe symbols. But my script seems to only read the first line of the DATA block showing me it contains 5 pipes. What I have tried
my $PipeCounter=0; # how many? my $Lookfor="|"; while(<DATA>) { $PipeCounter = () = $_ =~ /\Q$Lookfor/g; } print "Found $PipeCounter '$Lookfor'\n";
which shows me
Running Sanitize on DATA ... Found 5 '|'
Sample DATA:
2015|Art Of Computer Programming - Volume 4 Fascicle 6 Satisfiablility + (The)|Art Of Computer Programming - Volume 4 Fascicle 6 Satisfiablil +ity (The).pdf|Knuth,Donald E.|Programming;Reference|The never-ending +story .. this book has been decades in the making. Three volumes were + available for years but the master himself has added this addition t +o Chap. 7 'Combinatorial Searching'. 2010|Art Of Photography (The)|Art Of Photography (The).pdf|Barnbaum,Br +uce|Photography|A successful photograph does one of several things. I +t allows, or forces, the viewer to see something that he has looked a +t many times without really seeing; it shows him something he has nev +er previously encountered; or, it raises questions - perhaps ambiguou +s or unanswerable - that create mysteries, doubts, or uncertainties. +In other words, it expands our vision and our thoughts. It extends ou +r horizons. It evokes awe, wonder, amusement, compassion, horror, or +any of a thousand responses. It sheds new light on our world, raises +questions about our world, or creates its own world. 1994|Art Of Woodworking Sharpening And Tool Care (The)|Art Of Woodwork +ing Sharpening And Tool Care (The).pdf|Time-Life Books|Woodworking To +ols|Whether you're using a chisel or a router or a lathe, you know th +at a sharp tool is critical to doing a good job. It's also safer - a +dull tool requires more force, and more force = less control. This bo +ok covers the proper techniques for sharpening all manner of your woo +dworking tools - hand tools, power tool blades and bits, portable pow +er tools, and stationary power tools. Detailed photographs and illust +rations with excellent descriptions and instructions. 2017|Art and Craft of Problem Solving 3E (The)|Art and Craft of Proble +m Solving 3E (The).pdf|Zeitz,Paul|Mathematics;Logic;Calculus|This is +a book about mathematical problem solving for college-level novices. +By this I mean bright people who know some mathematics (ideally, at l +east some calculus), who enjoy mathematics, who have at least a vague + notion of proof, but who have spent most of their time doing exercis +es rather than problems.
Anyone shed some light on this please?

In reply to Count number of characters in a DATA block by Trudge

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.