How can I create a qr// in Perl 5.12 from C?

This has been working for me in 5.8 and 5.10, but in 5.12 my code creates this weird non-qr object:

# running "print Dumper($regex)"
$VAR1 = bless( do{/(my $o = '')}, 'Regexp' );

Whereas printing a qr// not created by my code looks like this:

# running "print Dumper(qr/foo/i)"
$VAR1 = qr/(?i-xsm:foo)/;

My code is basically:

REGEXP *rx = re_compile(pattern, flags);
SV *regex = sv_2mortal(newSVpv("",0));

sv_magic(regex, (SV*)rx, PERL_MAGIC_qr, 0, 0);

stash = gv_stashpv("Regexp", 0);
sv_bless(newRV((SV*)regex), stash);

Anyone know how to correctly create a regex from a string in 5.12?

How can I create QR code from MySQL data?

I need a script that creates a QR code using user data stored in a MySQL database. It should be loaded every time the user accesses his data. I’ve done some research and I’ve found a library that may

How can I create XML from Perl?

I need to create XML in Perl. From what I read, XML::LibXML is great for parsing and using XML that comes from somewhere else. Does anyone have any suggestions for an XML Writer? Is XML::Writer still

How to create a QR code application?

Can you please explain me How actually QR codes are created and How they are tracked. Generated codes are stored in a DB. I am actually confused about how QR code reader application works. If I create

How can I create a Postgres database in Perl?

How can I create a Postgres database from Perl? This is not documented in the Perl Postgres DBI driver DBD::Pg (or pretty much anywhere else). I need to be able to create a scratch database from my pr

How can I use a C++ class from Perl?

I have a set of classes written in C++. What would be best way to call them from a Perl script? Thanks.

How can I create or read OpenOffice spreadsheets from Perl?

What is a good way to create and read an OpenOffice spreadsheet in Perl?

How can I use Perl 5 modules from Perl 6?

Is the a way to use Perl 5 modules from CPAN from Rakudo Perl 6? For example, how can I use the venerable Perl 5 module, CGI, which hasn’t been ported yet, in Perl 6. Update: And what this funky code

How can I read qr code inside GDK app?

I want to read qr code from GDK app to get authorization token. Is there any build in methods to read QR codes in GDK?

Perl qr// operation

i have a question about Perl qr operator: #!/usr/bin/perl -w &mysplit(a:b:c, /:/); sub mysplit { my($str, $pattern) = @_; my @arr = split $pattern, $str; print @arr/n; } The result is: U

How can I use a C linked list from Perl XS?

I writing programing with Perl and XS. I need to display and do some operations that use a linked list from C. How can I accomplish that?

Answers

Take a look at the comments in this answer by hobbs. I’ve copied it below for ease of reading:

Regex objects actually get slightly more “core” in 5.12.0, as they’re now references to scalars of type REGEXP rather than references to scalars with magic. This is, however, completely invisible to user code, unless you manage to bypass overloaded stringification, in which case you’ll notice that regexes now print as Regexp=REGEXP(0x1234567) instead of Regexp=SCALAR(0x1234567)

I’m not especially familiar with XS, but I suspect you can’t use a scalar value any more to create your regex.

Perl 5.12 changed regexps to be first class objects, which you find as part of the tangential discussion in How do I check if a scalar has a compiled regex it in?.

I’m not an XS person, so I don’t know what you need to change in your code to make it work out. Searching for ‘REGEXP’ in the perl sources shows the fixes they made to the core modules to use the new stuff.

Thanks for putting me on the right track, guys, it turns out I was seriously overthinking this. They just cut out the magic line and don’t create the PV.

This is all you need to do in Perl 5.12:

REGEXP *rx = re_compile(pattern, flags);
SV *regex = newRV((SV*)rx);

stash = gv_stashpv("Regexp", 0);
sv_bless(regex, stash);