Bareword encontrado donde el operador esperaba en -e línea 1, cerca de "9A"
Frecuentes
Visto 3,827 veces
1
¿Por qué recibo un error de sintaxis?
% perl -ne 'if (/https://([-.0-9A-Za-z]+\.[-0-9A-Za-z]+)/) { print $1 ; }'
Bareword found where operator expected at -e line 1, near "9A"
(Missing operator before A?)
Bareword found where operator expected at -e line 1, near "9A"
(Missing operator before A?)
syntax error at -e line 1, near "9A"
syntax error at -e line 1, near ";}"
Execution of -e aborted due to compilation errors.
2 Respuestas
5
If the regex contains slashes, use a different character and the explicit m
operador:
perl -ne 'if (m%https://([-.0-9A-Za-z]+\.[-0-9A-Za-z]+)%) { print $1 ; }'
o:
perl -ne 'print $1 if m{https://([-.0-9A-Za-z]+\.[-0-9A-Za-z]+)}'
respondido 27 nov., 13:05
3
You need backslashes in front of the // after https:
perl -ne 'if (/https:\/\/([-.0-9A-Za-z]+\.[-0-9A-Za-z]+)/) { print $1 ; }'
Otherwise it thinks the regex is already over.
respondido 27 nov., 13:05
duh, makes sense! \o\ |o| /o/ Is there any other way, to avoid the hand waving? ^_^ - cnst
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas perl or haz tu propia pregunta.
You weren't paying attention to my answer to your question on
sed
,awk
,perl
orlex
— find strings by prefix+regex ignoring rest of input. It demonstrated the techniques shown in the answers here. - Jonathan Leffler@JonathanLeffler, I did this independently (based on stackoverflow.com/a/20172099/1122270) and when your answer only had
sed
in it (note the missing-l
here, too), but thanks for your help! - cnst