Hello,
I have been tasked with "correcting" certain items in SVG files. I have never used Perl and after a crash course (using PerlMonks, Stack Overflow, etc.) I can successfully read the SVG file line by line and correct the necessary lines. My final problem, and this is admittedly because of my inexperience, I cannot figure out how to grab the current line so I can do a smartmatch (or something similar). All I need to do is make sure that the current line starts with "<path" and process that line if so. Below is the (partial) code where I read in the file and loop through the lines to make the corrections.
EDIT - Ihave added more of the code to show what I want to do with smartmatch - NOTE thta target is set like so:
my $target = '<path';
opendir IN, $dirname;
my @in = grep { /^[^.]/ } readdir IN;
closedir IN;
for my $in (@in) {
open IN, '<', "$dirname/$in" || next;
open OUT, '>', "$outdirname/$in" || die "can't open file output/$in"
+;
foreach(<IN>) { #read file line by line
# Strings to correct Note: Escaped ( with \
s/rotate\(-180/rotate\(-0/g;
# Look at the current line
my @look_in = <IN>;
# <path is in this line, process line
if( $target ~~ @look_in) {
for my $key (keys %stroke_width_hash) {
s/$key/$stroke_width_hash{$key}/g;
}
}
# Print out line to OUT file
print OUT $_;
}
close OUT;
close IN;
}
I have tried (sad attempts):
Print (<IN>)
Print IN
etc.
But none of these are grabbing the actual text for that line
Any help will be greatly appreciated...
Charles
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.