[LUGOS] Obdelovanje dn v perlu-dodatek

Matija Grabnar matija+lugos at serverflow.com
Thu Jul 6 10:57:30 CEST 2006


matjaz.demsar at lj-mlek.si wrote:
>
> Prehitro sem poslal prejÅ¡nje sporoÄilo, se opraviÄujem
>
> if ($line =~ /^(\S+)\.\S+\,(\d+)\,(\d+)\,(\d+)\.\d+/) {
>
> Težava je v obliki podatkov. Ti so zapisani v obliki
>
> TALLY_T6180_VRS.Skladisca.Logistika.Trzenje.Ljubljana.LM,3,17,126
>
> Za obdelavo potrebujem samo ime tiskalnika, torej TALLY_T6180_VRS, v bazo pa skripta vpiÅ¡e "TALLY_T6180_VRS.Skladisca.Logistika.Trzenje.Ljubljana". To je logiÄno, ker perl dela v 
"greedy" naÄinu in pobere Äim veÄ do zadnje pike. Telovadil sem tudi z ? vendar rezultat ni bil v okviru priÄakovanega :(
>
> Ima kdo mogoÄe kakÅ¡no idejo, kako bi odrezal string pri prvi piki?
Ce zelis non-greedy matching, zamenjaj + z +?.

Kot pravi perldoc perlre:
By default, a quantified subpattern is "greedy", that is, it will match
as many times as possible (given a particular starting location) while
still allowing the rest of the pattern to match. If you want it to
match the minimum number of times possible, follow the quantifier with
a "?". Note that the meanings donât change, just the "greediness":

*? Match 0 or more times
+? Match 1 or more times
?? Match 0 or 1 time
{n}? Match exactly n times
{n,}? Match at least n times
{n,m}? Match at least n but not more than m times



More information about the lugos-list mailing list